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

namespace Dao.Implement
{
    public class HotelSeasonRepository : RepositoryBase<HotelSeason>, IHotelSeasonRepository
    {
        public IQueryable<HotelSeason> LoadAllByPage(out long total, int page, int rows, string order, string sort)
        {
            var list = this.LoadAll();
            total = list.LongCount();
            list = list.OrderBy(sort + " " + order);
            list = list.Skip((page - 1) * rows).Take(rows);
            return list;
        }

        public HotelSeason LoadByHotelID(int hotelID)
        {
            return this.LoadAll().Where(r => r.SysHotel.ID == hotelID).FirstOrDefault();
        }
        /// <summary>
        /// 重载删除，只做标记
        /// </summary>
        /// <param name="id"></param>
        public override void Delete(object id)
        {
            var entity = this.HibernateTemplate.Get<HotelSeason>(id);
            if (entity == null)
            {
                return;
            }
            entity.IsDeleted = true;
            //entity.Last_Modified_Time = DateTime.Now;
            this.HibernateTemplate.Update(entity);
        }
        /// <summary>
        /// 重载删除，只做标记
        /// </summary>
        /// <param name="idList"></param>
        public override void Delete(IList<object> idList)
        {
            foreach (var id in idList)
            {
                var entity = this.HibernateTemplate.Get<HotelSeason>(id);
                if (entity == null)
                {
                    return;
                }
                entity.IsDeleted = true;
                //entity.Last_Modified_Time = DateTime.Now;
                this.HibernateTemplate.Update(entity);
            }
        }
    }
}
