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

namespace Dao.Implement
{
    public class RoomTypeChannelsRepository : RepositoryBase<RoomTypeChannels>, IRoomTypeChannelsRepository
    {
        public IQueryable<RoomTypeChannels> LoadAllByPage(out long total, int page, int rows, string order, string sort, int roomTypeId)
        {
            var list = this.LoadAll();

            list = list.Where(r => r.RoomType != null && r.RoomType.ID == roomTypeId);

            total = list.LongCount();

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

            return list;
        }

        public void DeleteByRoomTypeID(int roomTypeID)
        {
            IList<RoomTypeChannels> lists = this.LoadAll().Where(r => r.RoomType.ID == roomTypeID).ToList();
            foreach (RoomTypeChannels list in lists)
            {
                this.Delete(list.ID);
            }
        }
    }
}
