using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.ScoreManage; using System.Linq.Expressions; using EMIS.Entities; using EMIS.ViewModel; namespace EMIS.DataLogic.ScoreManage { public class ScoreParameterSettingDAL { public ScoreParameterSettingRepository ScoreParameterSettingRepository { get; set; } public DictionaryItemRepository DictionaryItemRepository { get; set; } public IQueryable GetScoreParameterSettingViewQueryable(Expression> exp) { var query = from a in ScoreParameterSettingRepository.GetList(exp) select a; return query; } public IQueryable GetScoreParameterSettingViewQueryable() { var sql = (from detail in ScoreParameterSettingRepository.Entities where detail.ExamsTypeID == null && detail.CourseTypeID == null select new ScoreParameterSettingView { ExamsTypeID = null, ExamsTypeName = null, CourseTypeID = null, CourseTypeName = null, ScoreFormulaID = detail.ScoreFormulaID, IsTotalFormula = detail.IsTotalFormula ?? false, CreditFormulaID = detail.CreditFormulaID, IsCreditFormula = detail.IsCreditFormula ?? false, GradePointFormulaID = detail.GradePointFormulaID, IsGradePointFormula = detail.IsGradePointFormula ?? false, OrderNo = (detail.ExamsTypeID ?? 0) * (detail.CourseTypeID ?? 0) }).Concat( from category in DictionaryItemRepository.GetList(x => x.DictionaryCode == DictionaryItem.CF_ExamsCategory.ToString()) join detail in ScoreParameterSettingRepository.Entities on new { ExamsTypeID = category.Value, CourseTypeID = (int?)null } equals new { detail.ExamsTypeID, detail.CourseTypeID } into ddetail from detail in ddetail.DefaultIfEmpty() select new ScoreParameterSettingView { ExamsTypeID = category.Value, ExamsTypeName = category.Name, CourseTypeID = null, CourseTypeName = null, ScoreFormulaID = detail.ScoreFormulaID, IsTotalFormula = detail.IsTotalFormula ?? false, CreditFormulaID = detail.CreditFormulaID, IsCreditFormula = detail.IsCreditFormula ?? false, GradePointFormulaID = detail.GradePointFormulaID, IsGradePointFormula = detail.IsGradePointFormula ?? false, OrderNo = (detail.ExamsTypeID ?? 0) * (detail.CourseTypeID ?? 0) } ).Concat( from courseType in DictionaryItemRepository.GetList(x => x.DictionaryCode == DictionaryItem.CF_CourseType.ToString()) join detail in ScoreParameterSettingRepository.Entities on new { ExamsTypeID = (int?)null, CourseTypeID = courseType.Value } equals new { detail.ExamsTypeID, detail.CourseTypeID } into ddetail from detail in ddetail.DefaultIfEmpty() select new ScoreParameterSettingView { ExamsTypeID = null, ExamsTypeName = null, CourseTypeID = courseType.Value, CourseTypeName = courseType.Name, ScoreFormulaID = detail.ScoreFormulaID, IsTotalFormula = detail.IsTotalFormula ?? false, CreditFormulaID = detail.CreditFormulaID, IsCreditFormula = detail.IsCreditFormula ?? false, GradePointFormulaID = detail.GradePointFormulaID, IsGradePointFormula = detail.IsGradePointFormula ?? false, OrderNo = (detail.ExamsTypeID ?? 0) * (detail.CourseTypeID ?? 0) } ).Concat( from category in DictionaryItemRepository.GetList(x => x.DictionaryCode == DictionaryItem.CF_ExamsCategory.ToString()) join courseType in DictionaryItemRepository.GetList(x => x.DictionaryCode == DictionaryItem.CF_CourseType.ToString()) on true equals true join detail in ScoreParameterSettingRepository.Entities on new { ExamsTypeID = category.Value, CourseTypeID = courseType.Value } equals new { detail.ExamsTypeID, detail.CourseTypeID } into ddetail from detail in ddetail.DefaultIfEmpty() select new ScoreParameterSettingView { ExamsTypeID = category.Value, ExamsTypeName = category.Name, CourseTypeID = courseType.Value, CourseTypeName = courseType.Name, ScoreFormulaID = detail.ScoreFormulaID, IsTotalFormula = detail.IsTotalFormula ?? false, CreditFormulaID = detail.CreditFormulaID, IsCreditFormula = detail.IsCreditFormula ?? false, GradePointFormulaID = detail.GradePointFormulaID, IsGradePointFormula = detail.IsGradePointFormula ?? false, OrderNo = (detail.ExamsTypeID ?? 0) * (detail.CourseTypeID ?? 0) }); return sql; } } }