EvaluationIntTypeServices.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using EMIS.ViewModel.EvaluationManage;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.DataLogic.Common.EvaluationManage;
  9. using EMIS.Entities;
  10. using System.Linq.Expressions;
  11. namespace EMIS.CommonLogic.EvaluationManage
  12. {
  13. public class EvaluationIntTypeServices : BaseServices, IEvaluationIntTypeServices
  14. {
  15. public EvaluationIntTypeDAL evaluationIntTypeDAL { get; set; }
  16. /// <summary>
  17. /// 列表信息
  18. /// </summary>
  19. /// <param name="configuretView"></param>
  20. /// <param name="intType"></param>
  21. /// <param name="pageIndex"></param>
  22. /// <param name="pageSize"></param>
  23. /// <returns></returns>
  24. public IGridResultSet<EvaluationIntTypeView> GetEvaluationIntTypeViewGrid(ViewModel.ConfiguretView configuretView, int? intType, int pageIndex, int pageSize)
  25. {
  26. Expression<Func<EM_EvaluationIntType, bool>> exp = x => true;
  27. if (intType.HasValue && intType > 0)
  28. {
  29. exp = exp.And(x => x.EM_EvaluationTeachingMode.Select(w => w.TeachingModeID).Contains(intType));
  30. }
  31. var query = evaluationIntTypeDAL.GetEvaluationIntTypeQueryable(exp);
  32. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  33. {
  34. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  35. }
  36. var result = query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ToGridResultSet<EvaluationIntTypeView>(pageIndex, pageSize);
  37. var evaluationIntTypeIDList = result.rows.Select(x => x.EvaluationIntTypeID).ToList();
  38. var querEvaluationTeachingModeTypeView = evaluationIntTypeDAL.GetEvaluationTeachingModeTypeQuery(x => evaluationIntTypeIDList.Contains(x.EvaluationIntTypeID)).ToList();
  39. result.rows.ForEach(x => x.TeachingModeTypeViewList = new HashSet<TeachingModeTypeView>(querEvaluationTeachingModeTypeView.Where(y => y.EvaluationIntTypeID == x.EvaluationIntTypeID)));
  40. return result;
  41. }
  42. public List<EvaluationIntTypeView> GetEvaluationIntTypeViewList(ViewModel.ConfiguretView configuretView, int? intType)
  43. {
  44. Expression<Func<EM_EvaluationIntType, bool>> exp = x => true;
  45. if (intType.HasValue && intType > 0)
  46. {
  47. exp = exp.And(x => x.EM_EvaluationTeachingMode.Select(w => w.TeachingModeID).Contains(intType));
  48. }
  49. var query = evaluationIntTypeDAL.GetEvaluationIntTypeQueryable(exp);
  50. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  51. {
  52. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  53. }
  54. var result = query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ToList();
  55. var evaluationIntTypeIDList = result.Select(x => x.EvaluationIntTypeID).ToList();
  56. var querEvaluationTeachingModeTypeView = evaluationIntTypeDAL.GetEvaluationTeachingModeTypeQuery(x => evaluationIntTypeIDList.Contains(x.EvaluationIntTypeID)).ToList();
  57. result.ForEach(x => x.TeachingModeTypeViewList = new HashSet<TeachingModeTypeView>(querEvaluationTeachingModeTypeView.Where(y => y.EvaluationIntTypeID == x.EvaluationIntTypeID)));
  58. return result.ToList();
  59. }
  60. /// <summary>
  61. /// 编辑新增
  62. /// </summary>
  63. /// <param name="model"></param>
  64. public void SaveOrUpdateEvaluationIntType(EvaluationIntTypeView model)
  65. {
  66. if (model.EvaluationIntTypeID == Guid.Empty || model.EvaluationIntTypeID == null)
  67. {
  68. EM_EvaluationIntType evaluationIntType = new EM_EvaluationIntType();
  69. evaluationIntType.EvaluationIntTypeID = Guid.NewGuid();
  70. evaluationIntType.Code = model.Code;
  71. evaluationIntType.Name = model.Name;
  72. evaluationIntType.Remark = model.Remark;
  73. SetNewStatus(evaluationIntType);
  74. UnitOfWork.Add(evaluationIntType);
  75. if (model.TeachingModeTypeID == null || model.TeachingModeTypeID.Count() < 0)
  76. {
  77. throw new Exception("授课方式不能为空。");
  78. }
  79. model.TeachingModeTypeID.ForEach(x =>
  80. {
  81. EM_EvaluationTeachingMode evaluationTeachingMode = new EM_EvaluationTeachingMode();
  82. evaluationTeachingMode.EvaluationTeachingModeID = Guid.NewGuid();
  83. evaluationTeachingMode.EvaluationIntTypeID = evaluationIntType.EvaluationIntTypeID;
  84. evaluationTeachingMode.TeachingModeID = x;//授课方式
  85. SetNewStatus(evaluationTeachingMode);
  86. UnitOfWork.Add(evaluationTeachingMode);
  87. });
  88. }
  89. else
  90. {
  91. if (model.TeachingModeTypeID == null || model.TeachingModeTypeID.Count() < 0)
  92. {
  93. throw new Exception("授课方式不能为空。");
  94. }
  95. EM_EvaluationIntType evaluationIntType = evaluationIntTypeDAL.evaluationIntTypeRepository.
  96. GetSingle(x => x.EvaluationIntTypeID == model.EvaluationIntTypeID);
  97. evaluationIntType.Code = model.Code;
  98. evaluationIntType.Name = model.Name;
  99. evaluationIntType.Remark = model.Remark;
  100. Guid EvaluationIntTypeIDList = evaluationIntType.EvaluationIntTypeID;
  101. UnitOfWork.Delete<EM_EvaluationTeachingMode>(x => x.EvaluationIntTypeID == EvaluationIntTypeIDList);//先删除评价类型授课方式再重新添加
  102. SetModifyStatus(evaluationIntType);
  103. UnitOfWork.Update(evaluationIntType);
  104. model.TeachingModeTypeID.ForEach(x =>
  105. {
  106. EM_EvaluationTeachingMode evaluationTeachingMode = new EM_EvaluationTeachingMode();
  107. evaluationTeachingMode.EvaluationTeachingModeID = Guid.NewGuid();
  108. evaluationTeachingMode.EvaluationIntTypeID = evaluationIntType.EvaluationIntTypeID;
  109. evaluationTeachingMode.TeachingModeID = x;//授课方式
  110. SetNewStatus(evaluationTeachingMode);
  111. UnitOfWork.Add(evaluationTeachingMode);
  112. });
  113. }
  114. UnitOfWork.Commit();
  115. }
  116. /// <summary>
  117. /// 删除操作
  118. /// </summary>
  119. /// <param name="IntTypeIDs"></param>
  120. /// <returns></returns>
  121. public bool EvaluationIntTypeDelete(List<Guid> IntTypeIDs)
  122. {
  123. try
  124. {
  125. //设置极联删除~~
  126. UnitOfWork.Delete<EM_EvaluationTeachingMode>(x => IntTypeIDs.Contains((Guid)x.EvaluationIntTypeID));//删除评价类型授课方式
  127. UnitOfWork.Delete<EM_EvaluationIntType>(x => IntTypeIDs.Contains(x.EvaluationIntTypeID));//删除评价类型
  128. return true;
  129. }
  130. catch (Exception)
  131. {
  132. throw;
  133. }
  134. }
  135. /// <summary>
  136. /// 加载授课方式
  137. /// </summary>
  138. /// <param name="evaluationIntTypeID"></param>
  139. /// <returns></returns>
  140. public List<int> GetTeachingMode(Guid? evaluationIntTypeID)
  141. {
  142. return evaluationIntTypeDAL.GetTeachingModeTypeQueryble(evaluationIntTypeID);
  143. }
  144. public EvaluationIntTypeView GetEvaluationIntTypeView(Guid? evaluationIntTypeID)
  145. {
  146. EvaluationIntTypeView evaluationIntTypeView = new EvaluationIntTypeView();
  147. if (evaluationIntTypeID.HasValue && evaluationIntTypeID != Guid.Empty)
  148. {
  149. evaluationIntTypeView = evaluationIntTypeDAL.GetEvaluationIntTypeQueryable(x => true).Where(x => x.EvaluationIntTypeID == evaluationIntTypeID).FirstOrDefault();
  150. }
  151. return evaluationIntTypeView;
  152. }
  153. }
  154. }