using Edu.Common.Enum;
using Edu.Model.Entity.Scroll;
using Edu.Model.ViewModel.Scroll;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;

namespace Edu.Repository.Scroll
{
    /// <summary>
    /// 滚动开班上课时段仓储层
    /// </summary>
    public class RB_Scroll_CourseTimeRepository : BaseRepository<RB_Scroll_CourseTime>
    {

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_Scroll_CourseTime_ViewModel> GetList(RB_Scroll_CourseTime_ViewModel demodel)
        {
            DynamicParameters parameters = new DynamicParameters();
            string where = $@" 1=1 and r.{nameof(RB_Scroll_CourseTime_ViewModel.Status)} =0";
            if (demodel.Group_Id > 0)
            {
                where += $@" and r.{nameof(RB_Scroll_CourseTime_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (!string.IsNullOrEmpty(demodel.CourseTimeIds))
            {
                where += $@" and r.{nameof(RB_Scroll_CourseTime_ViewModel.Id)} in({demodel.CourseTimeIds})";
            }
            if (!string.IsNullOrEmpty(demodel.Name))
            {
                where += $@" and r.{nameof(RB_Scroll_CourseTime_ViewModel.Name)} like @Name";
                parameters.Add("Name", "%" + demodel.Name + "%");
            }

            string sql = $@" 
SELECT * From RB_Scroll_CourseTime r
WHERE {where} 
ORDER BY r.Id asc ";
            return Get<RB_Scroll_CourseTime_ViewModel>(sql, parameters).ToList();
        }
    }
}