using Edu.Model.ViewModel.Course;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;

namespace Edu.Repository.Course
{

    /// <summary>
    /// 课程作业仓储层
    /// </summary>
    public class RB_Course_JobRepository : BaseRepository<Model.Entity.Course.RB_Course_Job>
    {
        /// <summary>
        /// 获取课程作业分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Course_Job_ViewModel> GetCourseJobPageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Course_Job_ViewModel query)
        {
            var parameters = new DynamicParameters();
            rowsCount = 0;
            if (query == null)
            {
                return new List<RB_Course_Job_ViewModel>();
            }
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT * 
FROM  RB_Course_Job
WHERE 1=1 
");
            if (query.CourseId > 0)
            {
                builder.AppendFormat(" AND {0}={1} ", nameof(RB_Course_Job_ViewModel.CourseId), query.CourseId);
            }
            if (query.Group_Id > 0)
            {
                builder.AppendFormat(" AND {0}={1} ", nameof(RB_Course_Job_ViewModel.Group_Id), query.Group_Id);
            }
            if (!string.IsNullOrEmpty(query.JobName))
            {
                builder.AppendFormat(" AND {0} LIKE @JobName ", nameof(RB_Course_Job_ViewModel.JobName));
                parameters.Add("JobName", "%" + query.JobName.Trim() + "%");
            }
            return GetPage<RB_Course_Job_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
        }
    }
}
