using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using Domain;
using System.Data;
using System.Data.SqlClient;

namespace Dao.Implement
{
    public class HostTimingControlRepository : RepositoryBase<HostTimingControl>, IHostTimingControlRepository
    {
        public IQueryable<HostTimingControl> 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 DataTable LoadHostTimingToExec()
        {
            IDbCommand cmd = Session.Connection.CreateCommand();
            cmd.CommandText = "LoadHostTimingToExec";
            cmd.CommandType = CommandType.StoredProcedure;
            IDbDataAdapter da = new SqlDataAdapter(cmd as SqlCommand);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
    }
}
