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 HostSceneRepository : RepositoryBase<HostScene>, IHostSceneRepository
    {
        public HostScene Get(int hostID, string groupAddress)
        {
            return LoadAll().FirstOrDefault(r => r.HostID == hostID && r.Scene.GroupAddress == groupAddress);
        }

        public IQueryable<HostScene> LoadByHostID(int hostID)
        {
            return LoadAll().Where(r => r.HostID == hostID);
        }

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

        public void DeteleByRoomTypeScene(int roomTypeSceneID)
        {
            Session.CreateSQLQuery("DELETE FROM tb_HostScene WHERE RoomTypeSceneID=?").SetInt32(0, roomTypeSceneID).ExecuteUpdate();
        }

        public void DeteleByRoomTypeScene(int hostID, int roomTypeSceneID)
        {
            Session.CreateSQLQuery("DELETE FROM tb_HostScene WHERE HostID=? and RoomTypeSceneID=?").SetInt32(0, hostID).SetInt32(1, roomTypeSceneID).ExecuteUpdate();
        }
    }
}
