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

namespace Edu.Repository.Exam
{
    /// <summary>
    /// 试卷题目分组仓储层
    /// </summary>
    public class RB_Examination_GroupRepository : BaseRepository<RB_Examination_Group>
    {
        /// <summary>
        /// 获取试卷题目列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Examination_Group_ViewModel> GetExaminationGroupListRepository(RB_Examination_Group_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.* 
FROM RB_Examination_Group AS A
WHERE 1=1 
");
           
            if (query != null)
            {
                if (query.PaperId > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Examination_Group_ViewModel.PaperId), query.PaperId);
                }
                if (!string.IsNullOrEmpty(query.QPaperIds))
                {
                    builder.AppendFormat(@" AND A.{0} IN({1}) ", nameof(RB_Examination_Group_ViewModel.PaperId), query.QPaperIds);
                }
            }
            return Get<RB_Examination_Group_ViewModel>(builder.ToString()).ToList();
        }
    }
}
