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

namespace Dao.Implement
{
    public class RoomTypeProgramFilesRepository : RepositoryBase<RoomTypeProgramFiles>, IRoomTypeProgramFilesRepository
    {
        public IQueryable<RoomTypeProgramFiles> LoadAllByPage(out long total, int page, int rows, string order, string sort, int roomTypeID)
        {
            var list = this.LoadAll().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<RoomTypeProgramFiles> lists = this.LoadAll().Where(r => r.RoomType.ID == roomTypeID).ToList();
            foreach (RoomTypeProgramFiles list in lists)
            {
                this.Delete(list.ID);
            }
        }
    }
}
