using Edu.Common.Enum;
using Edu.Model.ViewModel.Course;
using Edu.Repository.Course;
using System;
using System.Collections.Generic;
using System.Text;
using VT.FW.DB;

namespace Edu.Module.Course
{
    /// <summary>
    /// 教室管理处理类
    /// </summary>
    public class ClassRoomModule
    {
        /// <summary>
        /// 教室管理仓储层对象
        /// </summary>
        private readonly RB_Class_RoomRepository class_RoomRepository = new RB_Class_RoomRepository();
        /// <summary>
        /// 教室异常仓储对象
        /// </summary>
        private readonly RB_Class_RoomUseLogRepository class_RoomUseLogRepository = new RB_Class_RoomUseLogRepository();

        #region 教室管理

        /// <summary>
        /// 获取教室分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_Room_ViewModel> GetClassRoomPageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Class_Room_ViewModel query)
        {
            return class_RoomRepository.GetClassRoomPageListRepository(pageIndex, pageSize, out rowsCount, query);
        }

        /// <summary>
        /// 获取教室列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_Room_ViewModel> GetClassRoomListRepository(RB_Class_Room_ViewModel query)
        {
            return class_RoomRepository.GetClassRoomListRepository(query);
        }


        /// <summary>
        /// 获取教室列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_Room_ViewModel> GetClassRoomList(RB_Class_Room_ViewModel query)
        {
            return class_RoomRepository.GetClassRoomList(query);
        }



        /// <summary>
        /// 新增修改教室
        /// </summary>
        /// <param name="extModel"></param>
        /// <returns></returns>
        public bool SetClassRoomModule(RB_Class_Room_ViewModel extModel)
        {
            bool flag = false;
            if (extModel.RoomId > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Class_Room_ViewModel.RoomName),extModel.RoomName },
                    {nameof(RB_Class_Room_ViewModel.UpdateBy),extModel.UpdateBy },
                    {nameof(RB_Class_Room_ViewModel.UpdateTime),extModel.UpdateTime },
                    {nameof(RB_Class_Room_ViewModel.School_Id),extModel.School_Id },
                    {nameof(RB_Class_Room_ViewModel.SeatNum),extModel.SeatNum },
                    {nameof(RB_Class_Room_ViewModel.RoomPic),extModel.RoomPic },
                    {nameof(RB_Class_Room_ViewModel.StartTime),extModel.StartTime },
                    {nameof(RB_Class_Room_ViewModel.EndTime),extModel.EndTime },
                    {nameof(RB_Class_Room_ViewModel.TotalHour),extModel.TotalHour },
                };
                flag = class_RoomRepository.Update(fileds, new WhereHelper(nameof(RB_Class_Room_ViewModel.RoomId), extModel.RoomId));
            }
            else
            {
                var newId = class_RoomRepository.Insert(extModel);
                extModel.RoomId = newId;
                flag = newId > 0;
            }
            return flag;
        }


        /// <summary>
        /// 根据班级编号获取教室详细信息
        /// </summary>
        /// <param name="RoomId"></param>
        /// <returns></returns>
        public RB_Class_Room_ViewModel GetClassRoomModule(object RoomId)
        {
            return class_RoomRepository.GetEntity<RB_Class_Room_ViewModel>(RoomId);
        }

        /// <summary>
        /// 删除教室
        /// </summary>
        /// <param name="RoomId"></param>
        /// <param name="Status">状态</param>
        /// <returns></returns>
        public bool RemoveClassRoomModule(object RoomId, int Status)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                { nameof(RB_Class_Room_ViewModel.Status),Status},
            };
            return class_RoomRepository.Update(fileds, new WhereHelper(nameof(RB_Class_Room_ViewModel.RoomId), RoomId));
        }

        #endregion

        #region 教室异常

        /// <summary>
        /// 获取教异常分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_RoomUseLog_ViewModel> GetClassRoomUseLogPageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Class_RoomUseLog_ViewModel query)
        {
            return class_RoomUseLogRepository.GetClassRoomUseLogPageListRepository(pageIndex, pageSize, out rowsCount, query);
        }


        /// <summary>
        /// 获取教室异常列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_RoomUseLog_ViewModel> GetClassRoomUseLogListRepository(RB_Class_RoomUseLog_ViewModel query)
        {
            return class_RoomUseLogRepository.GetClassRoomUseLogListRepository(query);
        }


        /// <summary>
        /// 获取实体信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Model.Entity.Course.RB_Class_RoomUseLog GetRoomUseLogEntity(object Id)
        {
            return class_RoomUseLogRepository.GetEntity(Id);
        }


        /// <summary>
        /// 新增/修改教室异常
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int SetRoomUseLog(RB_Class_RoomUseLog_ViewModel model)
        {
            if (model.RoomErrorId == 0)
            {
                return class_RoomUseLogRepository.Insert(model);
            }
            else
            {

                Dictionary<string, object> fileds = new Dictionary<string, object>() ;
                if (model.UpdateTime.HasValue)
                {
                    fileds = new Dictionary<string, object>()
                    {
                        
                        {nameof(RB_Class_RoomUseLog_ViewModel.UpdateTime),model.UpdateTime },
                        {nameof(RB_Class_RoomUseLog_ViewModel.Participants),model.Participants }
                    };
                }
                else {
                    fileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Class_RoomUseLog_ViewModel.Participants),model.Participants }
                    };
                }
                bool flag = class_RoomUseLogRepository.Update(fileds, new WhereHelper(nameof(RB_Class_RoomUseLog_ViewModel.RoomErrorId), model.RoomErrorId));
                if (flag)
                {
                    return model.RoomErrorId;
                }
                else
                {
                    return 0;
                }
            }
        }

        #endregion
    }
}
