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

namespace Dao.Implement
{
	public class FaultRecordsRepository : RepositoryBase<FaultRecord>, IFaultRecordsRepository
	{
        public IQueryable<FaultRecord> 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 string GenerateFaultNumber()
		{
			return Session.GetNamedQuery("GenerateFaultNumber").UniqueResult().ToString();
		}

		public int GetFaultsCount(int faultTypeID)
		{
			return base.LoadAll().Count(r => r.FaultType.ID == faultTypeID);
		}
	}
}
