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>
        /// <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="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 },
                };
                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));
        }
    }
}
