using Edu.Model.Entity.Course;
using Edu.Model.ViewModel.Course;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Edu.Repository.Course
{
    /// <summary>
    /// 课程阶梯价格仓储层
    /// </summary>
    public class RB_Class_StepPriceRepository : BaseRepository<RB_Class_StepPrice>
    {
        /// <summary>
        /// 获取课程阶梯价格列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_StepPrice_ViewModel> GetClassStepPriceListRepository(RB_Class_StepPrice_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat(@" 
SELECT *
FROM RB_Class_StepPrice
WHERE 1=1
");
            if (query != null)
            {
                if (query.ClassId>0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_StepPrice_ViewModel.ClassId), query.ClassId);
                }
                if (!string.IsNullOrEmpty(query.QClassIds))
                {
                    builder.AppendFormat(" AND {0} IN ({1}) ", nameof(RB_Class_StepPrice_ViewModel.ClassId), query.QClassIds);
                }
            }
            return Get<RB_Class_StepPrice_ViewModel>(builder.ToString()).ToList();
        }

        /// <summary>
        /// 根据班级编号删除班级阶梯价格
        /// </summary>
        /// <param name="ClassId">班级编号</param>
        /// <returns></returns>
        public bool DeleteClassStepPriceRepository(int ClassId)
        {
            return base.DeleteOne(new VT.FW.DB.WhereHelper(nameof(RB_Class_StepPrice_ViewModel.ClassId), ClassId));
        }
    }
}
