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 TrialLessonModule
    {
        /// <summary>
        /// 试听课程仓储层对象
        /// </summary>
        private readonly RB_TrialLessonRepository trialLessonRepository = new RB_TrialLessonRepository();

        /// <summary>
        /// 获取试听课程分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCuont"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_TrialLesson_Extend> GetTrialLessonPageModule(int pageIndex, int pageSize, out long rowsCuont, RB_TrialLesson_Extend query)
        {
            var list = trialLessonRepository.GetTrialLessonPageRepository(pageIndex, pageSize, out rowsCuont, query);
            return list;
        }

        /// <summary>
        /// 获取试听课程列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_TrialLesson_Extend> GetTrialLessonListModule(RB_TrialLesson_Extend query)
        {
            var list = trialLessonRepository.GetTrialLessonListRepository(query);
            return list;
        }


        /// <summary>
        /// 新增修改试听课程
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetTrialLessonModule(RB_TrialLesson_Extend model)
        {
            bool flag = false;
            if (model.Id > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_TrialLesson_Extend.LessonName),model.LessonName },
                    {nameof(RB_TrialLesson_Extend.TeacherId),model.TeacherId },
                    {nameof(RB_TrialLesson_Extend.ClassHourFee),model.ClassHourFee },
                    {nameof(RB_TrialLesson_Extend.CalculateType),model.CalculateType },
                };
                flag = trialLessonRepository.Update(fileds, new WhereHelper(nameof(RB_TrialLesson_Extend.Id), model.Id));
            }
            else
            {
                var newId = trialLessonRepository.Insert(model);
                model.Id = newId;
                flag = newId > 0;
            }
            return flag;
        }

        /// <summary>
        /// 根据编号获取试听课程信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public RB_TrialLesson_Extend GetTrialLessonModule(object Id)
        {
            var extModel = trialLessonRepository.GetEntity<RB_TrialLesson_Extend>(Id);
            return extModel;
        }

        /// <summary>
        /// 根据编号删除试听课程
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool RemoveTrialLessonModule(object Id)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                {nameof(RB_TrialLesson_Extend.Status), (int)DateStateEnum.Delete},
            };
            bool flag = trialLessonRepository.Update(fileds, new WhereHelper(nameof(RB_TrialLesson_Extend.Id), Id));
            return flag;
        }
    }
}
