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

namespace Edu.Repository.Exam
{
    /// <summary>
    /// 单词测试仓储层
    /// </summary>
    public class RB_StuWords_ExamRepository : BaseRepository<RB_StuWords_Exam>
    {
        /// <summary>
        /// 获取学员单词考试分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_StuWords_Exam_Extend> GetStuWordsExamPageRepository(int pageIndex, int pageSize, out long rowsCount, RB_StuWords_Exam_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*
FROM RB_StuWords_Exam AS A
WHERE 1=1
");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_StuWords_Exam_Extend.Group_Id), query.Group_Id);
                }
                if (query.Stu_Account_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_StuWords_Exam_Extend.Stu_Account_Id), query.Stu_Account_Id);
                }
                if (query.CourseId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_StuWords_Exam_Extend.CourseId), query.CourseId);
                }
                if (query.ChapterId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_StuWords_Exam_Extend.ChapterId), query.ChapterId);
                }
            }
            return GetPage<RB_StuWords_Exam_Extend>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }


        /// <summary>
        /// 获取学员单词考试列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_StuWords_Exam_Extend> GetStuWordsExamListRepository(RB_StuWords_Exam_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*
FROM RB_StuWords_Exam AS A
WHERE 1=1
");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_StuWords_Exam_Extend.Group_Id), query.Group_Id);
                }
                if (query.Stu_Account_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_StuWords_Exam_Extend.Stu_Account_Id), query.Stu_Account_Id);
                }
                if (query.CourseId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_StuWords_Exam_Extend.CourseId), query.CourseId);
                }
                if (query.ChapterId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_StuWords_Exam_Extend.ChapterId), query.ChapterId);
                }
            }
            return Get<RB_StuWords_Exam_Extend>(builder.ToString()).ToList();
        }
    }
}
