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

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

            total = list.LongCount();

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

            return list;
        }

        public IQueryable<RoomTypeScene> LoadAllByPage(out long total, int page, int rows, string order, string sort, int hotelID, int roomTypeId)
        {
            var list = this.LoadAll();

            list = list.Where(r => r.RoomType.HotelID == hotelID && (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 RoomTypeScene Get(int roomTypeID, string groupAddress)
        {
            return LoadAll().FirstOrDefault(r => r.RoomType.ID == roomTypeID && r.GroupAddress == groupAddress);
        }

        public IList<RoomTypeScene> LoadAll(RoomType roomType)
        {
            return LoadAll().Where(r => r.RoomType != null && r.RoomType == roomType).ToList();
        }
    }
}
