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_Course_StepPriceRepository : BaseRepository<RB_Course_StepPrice>
    {
        /// <summary>
        /// 获取课程阶梯价格列表
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Course_StepPrice_ViewModel> GetCourseStepPriceListRepository(RB_Course_StepPrice_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(@"
SELECT *
FROM RB_Course_StepPrice
WHERE 1=1
");
            if (query != null)
            {
                if (query.CourseId > 0)
                {
                    builder.AppendFormat(@" AND {0}={1} ", nameof(RB_Course_StepPrice_ViewModel.CourseId), query.CourseId);
                }
                if (!string.IsNullOrEmpty(query.QCourseIds))
                {
                    builder.AppendFormat(@" AND {0} IN({1}) ", nameof(RB_Course_StepPrice_ViewModel.CourseId), query.QCourseIds);
                }
            }
            return Get<RB_Course_StepPrice_ViewModel>(builder.ToString()).ToList();
        }

        /// <summary>
        /// 根据课程编号删除课程阶梯价格
        /// </summary>
        /// <param name="CourseId"></param>
        /// <returns></returns>
        public bool DeleteStepPriceRepository(int CourseId)
        {
            bool flag = base.DeleteOne(new VT.FW.DB.WhereHelper(nameof(RB_Course_StepPrice_ViewModel.CourseId), CourseId));
            return flag;
        }
    }
}
