using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain;
using System.Data;
using System.Data.SqlClient;

namespace Dao.Implement
{
    public class HostAirRepository : RepositoryBase<HostAir>, IHostAirRepository
    {
        public IQueryable<HostAir> LoadByHostID(int hostID)
        {
            return LoadAll().Where(r => r.HostID == hostID);
        }

        public void DeteleByHostID(int hostID)
        {
			Session.CreateSQLQuery("DELETE FROM tb_HostAir WHERE HostID=?").SetInt32(0, hostID).ExecuteUpdate();
        }

        public HostAir Get(int hostID, string modalAddress)
        {
            return LoadAll().FirstOrDefault(r => r.HostID == hostID && r.Modal.ModalTypeName == modalAddress);
        }

        public void DeteleByRoomTypeAirID(int hostID, int roomTypeAir)
        {
            var list = LoadAll().FirstOrDefault(r => r.HostID == hostID && r.Modal.ID == roomTypeAir);

            if (list != null)
            {
                Session.Delete(list);
                Session.Flush();
            }
        }
    }
}
