EvaluationTypeServices.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.EvaluationManage;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel;
  9. using System.Linq.Expressions;
  10. using EMIS.ViewModel.EvaluationManage;
  11. using EMIS.CommonLogic.SystemServices;
  12. namespace EMIS.CommonLogic.EvaluationManage
  13. {
  14. public class EvaluationTypeServices : BaseServices, IEvaluationTypeServices
  15. {
  16. public EvaluationTypeDAL evaluationTypeDAL { get; set; }
  17. public ISerialNumberServices SerialNumberServices { get; set; }
  18. /// <summary>
  19. /// 查询参评类型信息
  20. /// </summary>
  21. /// <param name="configuretView">查询条件实体</param>
  22. /// <param name="pageIndex">页码</param>
  23. /// <param name="pageSize">显示页数</param>
  24. /// <returns></returns>
  25. public IGridResultSet<EvaluationTypeView> GetEvaluationTypeViewGrid(ConfiguretView configuretView, int? isStudent, int? isDefault, int pageIndex, int pageSize)
  26. {
  27. var query = evaluationTypeDAL.GetEvaluationTypeQueryable(x => true);
  28. if (isStudent.HasValue && isStudent > -1)
  29. {
  30. bool student = isStudent == 1 ? true : false;
  31. query = query.Where(x => x.IsStudent == student);
  32. }
  33. if (isDefault.HasValue && isDefault > -1)
  34. {
  35. bool isdefault = isDefault == 1 ? true : false;
  36. query = query.Where(x => x.IsDefault == isdefault);
  37. }
  38. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  39. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.Name).ToGridResultSet<EvaluationTypeView>(pageIndex, pageSize);
  40. return query.OrderByDescending(x => x.Name).ToGridResultSet<EvaluationTypeView>(pageIndex, pageSize);
  41. }
  42. /// <summary>
  43. /// 查询参评类型信息
  44. /// </summary>
  45. /// <param name="configuretView">查询条件实体</param>
  46. /// <returns></returns>
  47. public List<EvaluationTypeView> GetEvaluationTypeViewList(ConfiguretView configuretView, int? isStudent, int? isDefault)
  48. {
  49. var query = evaluationTypeDAL.GetEvaluationTypeQueryable(x => true);
  50. if (isStudent.HasValue && isStudent > -1)
  51. {
  52. bool student = isStudent == 1 ? true : false;
  53. query = query.Where(x => x.IsStudent == student);
  54. }
  55. if (isDefault.HasValue && isDefault > -1)
  56. {
  57. bool isdefault = isDefault == 1 ? true : false;
  58. query = query.Where(x => x.IsDefault == isdefault);
  59. }
  60. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  61. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.CreateTime).ToList();
  62. return query.OrderByDescending(x => x.CreateTime).ToList();
  63. }
  64. /// <summary>
  65. /// 获取参评类型信息
  66. /// </summary>
  67. /// <param name="typeID">主键ID</param>
  68. /// <returns></returns>
  69. public EMIS.Entities.EM_EvaluationType GetEvaluationType(Guid? typeID)
  70. {
  71. //查询条件
  72. Expression<Func<EMIS.Entities.EM_EvaluationType, bool>> expression = (x => x.EvaluationTypeID == typeID.Value);
  73. return evaluationTypeDAL.evaluationTypeRepository.GetSingle(expression);
  74. }
  75. /// <summary>
  76. /// 获取参评类型信息
  77. /// </summary>
  78. /// <param name="intType">参评类型</param>
  79. /// <returns></returns>
  80. public EMIS.Entities.EM_EvaluationType GetEvaluationType(string Name)
  81. {
  82. //查询条件
  83. Expression<Func<EMIS.Entities.EM_EvaluationType, bool>> expression = (x => x.Name == Name);
  84. return evaluationTypeDAL.evaluationTypeRepository.GetSingle(expression);
  85. }
  86. /// <summary>
  87. /// 获取参评类型信息
  88. /// </summary>
  89. /// <param name="typeID">主键ID</param>
  90. /// <returns></returns>
  91. public EvaluationTypeView GetEvaluationTypeView(Guid? typeID)
  92. {
  93. EvaluationTypeView evaluationTypeView = new EvaluationTypeView();
  94. if (typeID.HasValue)
  95. evaluationTypeView = evaluationTypeDAL.GetEvaluationTypeQueryable(x => true).Where(x => x.TypeID == typeID).FirstOrDefault();
  96. return evaluationTypeView;
  97. }
  98. /// <summary>
  99. /// 添加
  100. /// </summary>
  101. /// <param name="evaluationType">实体</param>
  102. /// <returns></returns>
  103. public bool EvaluationTypeAdd(EMIS.Entities.EM_EvaluationType evaluationType)
  104. {
  105. try
  106. {
  107. UnitOfWork.Add(evaluationType);
  108. UnitOfWork.Commit();
  109. return true;
  110. }
  111. catch (Exception)
  112. {
  113. throw;
  114. }
  115. }
  116. /// <summary>
  117. /// 修改
  118. /// </summary>
  119. /// <param name="evaluationType">实体</param>
  120. /// <returns></returns>
  121. public bool EvaluationTypeUpdate(EMIS.Entities.EM_EvaluationType evaluationType)
  122. {
  123. try
  124. {
  125. UnitOfWork.Update(evaluationType);
  126. UnitOfWork.Commit();
  127. return true;
  128. }
  129. catch (Exception)
  130. {
  131. throw;
  132. }
  133. }
  134. /// <summary>
  135. /// 保存或新增参评类型
  136. /// </summary>
  137. /// <param name="model"></param>
  138. public void SaveOrUpdateEvaluationType(EvaluationTypeView model)
  139. {
  140. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  141. EM_EvaluationType entity;
  142. var entities = evaluationTypeDAL.evaluationTypeRepository.Entities.ToList();
  143. if (!model.TypeID.HasValue || model.TypeID == Guid.Empty)
  144. {
  145. entity = new EM_EvaluationType();
  146. entity.EvaluationTypeID = Guid.NewGuid();
  147. entity.CreateTime = DateTime.Now;
  148. entity.CreateUserID = user.UserID;
  149. //entity.Code = model.Code;
  150. UnitOfWork.Add(entity);
  151. }
  152. else
  153. {
  154. entity = entities.FirstOrDefault(w => w.EvaluationTypeID == model.TypeID);
  155. entities.Remove(entity);
  156. //UnitOfWork.Update(entity);
  157. }
  158. //entity.Name = model.Name;
  159. //entity.IsStudent = model.IsStudent;
  160. //entity.IsDefault = model.IsDefault;
  161. entity.StartTime = model.StartTime;
  162. entity.EndTime = model.EndTime;
  163. entity.Number = model.Number;
  164. entity.Remark = model.Remark;
  165. entity.ModifyUserID = user.UserID;
  166. entity.ModifyTime = DateTime.Now;
  167. if (entity.IsStudent == true)
  168. {
  169. //UnitOfWork.Update<EM_EvaluationType>(a => new EM_EvaluationType { IsDefault = false }, w => true);
  170. entities.ForEach(item => item.IsStudent = false);
  171. }
  172. UnitOfWork.Commit();
  173. }
  174. /// <summary>
  175. /// 删除
  176. /// </summary>
  177. /// <param name="typeIDs"></param>
  178. /// <returns></returns>
  179. public bool EvaluationTypeDelete(List<Guid> typeIDs)
  180. {
  181. try
  182. {
  183. UnitOfWork.Delete<EMIS.Entities.EM_EvaluationType>(x => typeIDs.Contains(x.EvaluationTypeID));
  184. UnitOfWork.Commit();
  185. return true;
  186. }
  187. catch (Exception)
  188. {
  189. throw;
  190. }
  191. }
  192. }
  193. }