using Edu.Model.Entity.Course;
using Edu.Model.ViewModel.Course;
using System.Text;
using System.Linq;

namespace Edu.Repository.Course
{
    /// <summary>
    /// 班级基础配置仓储层
    /// </summary>
    public class RB_Class_ConfigRepository : BaseRepository<RB_Class_Config>
    {
        /// <summary>
        /// 获取班级基础配置实体
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public RB_Class_Config_ViewModel GetClassConfigRepository(RB_Class_Config_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(@"
SELECT *
FROM RB_Class_Config
WHERE 1=1 
");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(@" AND {0}={1} ", nameof(RB_Class_Config_ViewModel.Group_Id), query.Group_Id);
                }
                if (query.ConfigId > 0)
                {
                    builder.AppendFormat(@" AND {0}={1} ", nameof(RB_Class_Config_ViewModel.ConfigId), query.ConfigId);
                }
            }
            return Get<RB_Class_Config_ViewModel>(builder.ToString()).FirstOrDefault();
        }
    }
}
