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

namespace Dao.Implement
{
    public class RoomCardRepository : RepositoryBase<RoomCard>, IRoomCardRepository
    {
        public IQueryable<RoomCard> LoadAllByPage(out long total, int page, int rows, string order, string sort, int hotelID)
        {
            var list = this.LoadAll().Where(r => r.HotelID == hotelID && r.RoomCardType != null);

            total = list.LongCount();

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

            return list;
        }

        public RoomCard Get(RoomCardType roomCardType, int hotelID)
        {
            return LoadAll().Where(r => r.RoomCardType != null && r.RoomCardType.ID == roomCardType.ID && r.HotelID == hotelID).FirstOrDefault();
        }

        public RoomCard GetByCarNumber(string cardNumber, int hotelID)
        {
            return LoadAll().Where(r => r.CardNumber == cardNumber && r.HotelID == hotelID).FirstOrDefault();
        }

        public RoomCard GetByCartType(RoomCardType cardType, string cardNumber, int hotelID)
        {
            return LoadAll().Where(r => r.RoomCardType != null && r.RoomCardType == cardType && r.CardNumber == cardNumber && r.HotelID == hotelID).FirstOrDefault();
        }
    }
}
