using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using Spring.Data.Core;
using Spring.Data.NHibernate.Generic.Support;
using Domain;

namespace Dao.Implement
{
    public class HostWordsReportRepository : RepositoryBase<HostWordsReport>, IHostWordsReportRepository
    {
        public IQueryable<HostWordsReport> LoadAllByPage(out long total, int page, int rows, string order, string sort, int hotelID)
        {
            var list = this.LoadAll().Where(r => r.HotelID == hotelID);

            total = list.LongCount();

            list = list.OrderBy(sort + " " + order);
            list = list.Skip((page - 1) * rows).Take(rows);

            return list;
        }

        public HostWordsReport Get(int hostID, string modalAddress)
        {
            return LoadAll().FirstOrDefault(r => r.HostID == hostID && r.ModalAddress == modalAddress);
        }

        public void DeteleByHostID(int hostID)
        {
            Session.CreateSQLQuery("DELETE FROM tb_HostWordsReport WHERE HostID=?").SetInt32(0, hostID).ExecuteUpdate();
        }
    }
}
