ScoreParamterCollegeSettingServices.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using EMIS.DataLogic.ScoreManage;
  7. using EMIS.ViewModel.ScoreManage;
  8. using EMIS.ViewModel;
  9. using EMIS.Entities;
  10. using Bowin.Common.Linq;
  11. using Bowin.Common.Linq.Entity;
  12. namespace EMIS.CommonLogic.ScoreManage
  13. {
  14. public class ScoreParamterCollegeSettingServices : BaseServices, IScoreParamterCollegeSettingServices
  15. {
  16. public ScoreParameterCollegeSettingDAL ScoreParameterCollegeSettingDAL { get; set; }
  17. public IGridResultSet<ScoreParameterCollegeSettingView> GetScoreParameterCollegeSettingViewGrid(ConfiguretView configuretView,
  18. Guid? collegeID, int? yearsID, int? pageIndex, int? pageSize)
  19. {
  20. Expression<Func<ER_ScoreParameterCollegeSetting, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  21. if (collegeID.HasValue)
  22. exp = exp.And(x => x.CollegeID == collegeID);
  23. if (yearsID.HasValue)
  24. exp = exp.And(x => x.Years == yearsID);
  25. var query = ScoreParameterCollegeSettingDAL.GetScoreParameterCollegeSettingViewQueryable(exp);
  26. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  27. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  28. return this.GetQueryByDataRangeByCollege(query)
  29. .OrderByDescending(x => x.Years)
  30. .ThenBy(x => x.CollegeNo.Length)
  31. .ThenBy(x => x.CollegeNo)
  32. .ToGridResultSet(pageIndex, pageSize);
  33. }
  34. public ScoreParameterCollegeSettingView GetScoreParameterCollegeSettingView(Guid scoreParameterCollegeSettingID)
  35. {
  36. Expression<Func<ER_ScoreParameterCollegeSetting, bool>> exp = (x => x.ScoreParameterCollegeSettingID == scoreParameterCollegeSettingID);
  37. return this.ScoreParameterCollegeSettingDAL.GetScoreParameterCollegeSettingViewQueryable(exp).FirstOrDefault();
  38. }
  39. public List<ScoreParameterSettingView> GetScoreParameterSettingViewForDetail(Guid? scoreParameterCollegeSettingID)
  40. {
  41. Expression<Func<ER_ScoreParameterCollegeSettingDetail, bool>> exp = (x => x.ScoreParameterCollegeSettingID == scoreParameterCollegeSettingID);
  42. return this.ScoreParameterCollegeSettingDAL.GetScoreParameterSettingViewQueryable(exp).ToList();
  43. }
  44. public void Delete(IList<Guid?> scoreParameterCollegeSettingIDList)
  45. {
  46. this.UnitOfWork.Remove<ER_ScoreParameterCollegeSettingDetail>(x => scoreParameterCollegeSettingIDList.Contains(x.ScoreParameterCollegeSettingID));
  47. this.UnitOfWork.Remove<ER_ScoreParameterCollegeSetting>(x => scoreParameterCollegeSettingIDList.Contains(x.ScoreParameterCollegeSettingID));
  48. this.UnitOfWork.Commit();
  49. }
  50. public void Save(ScoreParameterCollegeSettingView scoreParameterCollegeSettingView, IList<ScoreParameterSettingView> detailParameterViewList)
  51. {
  52. var entity = ScoreParameterCollegeSettingDAL.ScoreParameterCollegeSettingRepository.GetSingle(x => x.ScoreParameterCollegeSettingID == scoreParameterCollegeSettingView.ScoreParameterCollegeSettingID,
  53. (x => x.ER_ScoreParameterCollegeSettingDetail));
  54. if (entity == null)
  55. {
  56. entity = new ER_ScoreParameterCollegeSetting();
  57. entity.ScoreParameterCollegeSettingID = Guid.NewGuid();
  58. this.SetNewStatus(entity);
  59. UnitOfWork.Add(entity);
  60. }
  61. else
  62. {
  63. this.SetModifyStatus(entity);
  64. }
  65. var dupEntity = ScoreParameterCollegeSettingDAL.ScoreParameterCollegeSettingRepository.GetSingle(x => x.Years == scoreParameterCollegeSettingView.Years
  66. && x.CollegeID == scoreParameterCollegeSettingView.CollegeID
  67. && x.ScoreParameterCollegeSettingID != scoreParameterCollegeSettingView.ScoreParameterCollegeSettingID);
  68. if (dupEntity != null)
  69. {
  70. throw(new Exception("该年度已经有其他设置,无法保存。"));
  71. }
  72. entity.Years = scoreParameterCollegeSettingView.Years;
  73. entity.CollegeID = scoreParameterCollegeSettingView.CollegeID;
  74. entity.ScoreTypeID = scoreParameterCollegeSettingView.ScoreTypeID;
  75. this.UnitOfWork.Remove<ER_ScoreParameterCollegeSettingDetail>(x => x.ScoreParameterCollegeSettingID == entity.ScoreParameterCollegeSettingID);
  76. entity.ER_ScoreParameterCollegeSettingDetail = new HashSet<ER_ScoreParameterCollegeSettingDetail>();
  77. detailParameterViewList.ToList().ForEach(x => {
  78. var detail = new ER_ScoreParameterCollegeSettingDetail();
  79. detail.ScoreParameterCollegeSettingDetailID = Guid.NewGuid();
  80. detail.ScoreParameterCollegeSettingID = entity.ScoreParameterCollegeSettingID;
  81. detail.ExamsCategoryID = x.ExamsTypeID;
  82. detail.CourseTypeID = x.CourseTypeID;
  83. detail.ScoreFormulaID = x.ScoreFormulaID;
  84. detail.IsTotalFormula = x.IsTotalFormula;
  85. detail.CreditFormulaID = x.CreditFormulaID;
  86. detail.IsCreditFormula = x.IsCreditFormula;
  87. detail.GradePointFormulaID = x.GradePointFormulaID;
  88. detail.IsGradePointFormula = x.IsGradePointFormula;
  89. UnitOfWork.Add(detail);
  90. });
  91. this.UnitOfWork.Commit();
  92. }
  93. public ScoreParameterCollegeSettingView GetScoreParameterCollegeSettingView(Guid? collegeID, int? year)
  94. {
  95. var collegeSetting = ScoreParameterCollegeSettingDAL.GetScoreParameterCollegeSettingViewQueryable(x => x.CollegeID == collegeID
  96. && x.Years == year).FirstOrDefault();
  97. if (collegeSetting == null)
  98. {
  99. collegeSetting = ScoreParameterCollegeSettingDAL.GetScoreParameterCollegeSettingViewQueryable(x => x.CollegeID == null
  100. && x.Years == year).FirstOrDefault();
  101. }
  102. return collegeSetting;
  103. }
  104. }
  105. }