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_JobDetailsRepository : BaseRepository<RB_Course_JobDetails>
    {
        /// <summary>
        /// 获取课程作业题目列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Course_JobDetails_ViewModel> GetCourseJobDetailsListRepository(RB_Course_JobDetails_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*,B.Title,B.QuestionContent,B.DifficultyType,B.AnswerParse,B.QuestionTypeId,B.QuestionTypeKey,B.Knowledge,B.IsUpdateJobExam
      ,B.Answer,B.IsMutex,B.Category,B.LevelType
FROM RB_Course_JobDetails AS A INNER JOIN rb_question AS B ON A.QuestionId=B.QuestionId
WHERE 1=1
");
            if (query == null)
            {
                return new List<RB_Course_JobDetails_ViewModel>();
            }
            else
            {
                if (query.JobId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Course_JobDetails_ViewModel.JobId), query.JobId);
                }
            }
            return Get<RB_Course_JobDetails_ViewModel>(builder.ToString()).ToList();
        }

        /// <summary>
        /// 根据作业编号删除作业
        /// </summary>
        /// <param name="JobId"></param>
        /// <returns></returns>
        public bool RemoveCourseJobDetailsRepository(int JobId)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@" DELETE FROM RB_Course_JobDetails WHERE JobId={0} ", JobId);
            return base.Execute(builder.ToString()) > 0;
        }
    }
}
