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

namespace Edu.Repository.Grade
{
    public class RB_Class_LessonPlanProjectsRepository : BaseRepository<RB_Class_LessonPlanProjects>
    {
        /// <summary>
        /// 获取老师教案项目分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_LessonPlanProjects_ViewModel> GetLessonPlanProjectsPageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Class_LessonPlanProjects_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@" SELECT *  FROM RB_Class_LessonPlanProjects WHERE 1=1  ");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanProjects.Group_Id), query.Group_Id);
                }
                if (query.School_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanProjects.School_Id), query.School_Id);
                }
                if (query.LessonPlanId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanProjects.LessonPlanId), query.LessonPlanId);
                }
            }
            return GetPage<RB_Class_LessonPlanProjects_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }

        /// <summary>
        /// 获取老师教案项目分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_LessonPlanProjects_ViewModel> GetLessonPlanProjectsListRepository(RB_Class_LessonPlanProjects_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@" SELECT *  FROM RB_Class_LessonPlanProjects WHERE 1=1  ");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanProjects.Group_Id), query.Group_Id);
                }
                if (query.School_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanProjects.School_Id), query.School_Id);
                }
                if (query.LessonPlanId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanProjects.LessonPlanId), query.LessonPlanId);
                }
                if (!string.IsNullOrWhiteSpace(query.LessonPlanIds))
                {
                    builder.AppendFormat(" AND {0} in ({1}) ", nameof(RB_Class_LessonPlanProjects.LessonPlanId), query.LessonPlanIds);
                }
            }
            return Get<RB_Class_LessonPlanProjects_ViewModel>(builder.ToString()).ToList();
        }
    }
}
