using Edu.Model.ViewModel.Web;
using Edu.Repository.Web;
using System.Collections.Generic;
using VT.FW.DB;

namespace Edu.Module.Web
{
    /// <summary>
    /// 教师团队管理处理类
    /// </summary>
    public class WebTeacherModule
    {
        /// <summary>
        /// 教师团队管理仓储层对象
        /// </summary>
        private readonly RB_Web_TeacherRepository web_TeacherRepository = new RB_Web_TeacherRepository();

        /// <summary>
        /// 获取教师团队分页列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页显示调试</param>
        /// <param name="rowsCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Web_Teacher_ViewModel> GetWebTeacherPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Web_Teacher_ViewModel query)
        {
            return web_TeacherRepository.GetWebTeacherPageRepository(pageIndex, pageSize, out rowsCount, query);
        }

        /// <summary>
        /// 获取教师团队列表
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Web_Teacher_ViewModel> GetWebTeacherListModule(RB_Web_Teacher_ViewModel query)
        {
            return web_TeacherRepository.GetWebTeacherListRepository(query);
        }

        /// <summary>
        /// 新增修改教师团队
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetWebTeacherModule(RB_Web_Teacher_ViewModel model)
        {
            bool flag;
            if (model.Id > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Web_Teacher_ViewModel.Name),model.Name },
                    {nameof(RB_Web_Teacher_ViewModel.Icon),model.Icon },
                    {nameof(RB_Web_Teacher_ViewModel.Intro),model.Intro },
                    {nameof(RB_Web_Teacher_ViewModel.Type),model.Type },
                    {nameof(RB_Web_Teacher_ViewModel.Sex),model.Sex },
                };
                flag = web_TeacherRepository.Update(fileds, new WhereHelper(nameof(RB_Web_Teacher_ViewModel.Id), model.Id));
            }
            else
            {
                var newId = web_TeacherRepository.Insert(model);
                model.Id = newId;
                flag = newId > 0;
            }
            return flag;
        }

        /// <summary>
        /// 根据编号获取教师团队详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public RB_Web_Teacher_ViewModel GetWebTeacherModule(object Id)
        {
            return web_TeacherRepository.GetEntity<RB_Web_Teacher_ViewModel>(Id);
        }

        /// <summary>
        /// 修改教师团队状态
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="Status">0-正常,1-删除</param>
        /// <returns></returns>
        public bool RemoveWebTeacherStatusModule(int Id, int Status)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                {nameof(RB_Web_Teacher_ViewModel.Status),Status },
            };
            var flag = web_TeacherRepository.Update(fileds, new WhereHelper(nameof(RB_Web_Teacher_ViewModel.Id), Id));
            return flag;
        }
    }
}