CampusServices.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.Entities;
  7. using EMIS.ViewModel;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.DataLogic.Common.AdministrativeOrgan;
  10. using EMIS.Utility;
  11. using System.Linq.Expressions;
  12. namespace EMIS.CommonLogic.AdministrativeOrgan
  13. {
  14. public class CampusServices : BaseServices, ICampusServices
  15. {
  16. public CampusDAL CampusDAL { get; set; }
  17. /// <summary>
  18. /// 查询校区信息View
  19. /// </summary>
  20. /// <param name="configuretView"></param>
  21. /// <param name="pageIndex"></param>
  22. /// <param name="pageSize"></param>
  23. /// <returns></returns>
  24. public IGridResultSet<CampusView> GetCampusViewGrid(ConfiguretView configuretView, int pageIndex, int pageSize)
  25. {
  26. //校区信息
  27. Expression<Func<CF_Campus, bool>> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  28. var query = CampusDAL.GetCampusViewQueryable(expCampus);
  29. //查询条件
  30. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  31. {
  32. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  33. }
  34. return this.GetQueryByDataRangeByCampus(query)
  35. .OrderBy(x => x.No.Length).ThenBy(x => x.No)
  36. .ToGridResultSet<CampusView>(pageIndex, pageSize);
  37. }
  38. /// <summary>
  39. /// 查询校区信息List
  40. /// </summary>
  41. /// <param name="configuretView"></param>
  42. /// <returns></returns>
  43. public IList<CampusView> GetCampusViewList(ConfiguretView configuretView)
  44. {
  45. //校区信息
  46. Expression<Func<CF_Campus, bool>> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  47. var query = CampusDAL.GetCampusViewQueryable(expCampus);
  48. //查询条件
  49. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  50. {
  51. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  52. }
  53. return this.GetQueryByDataRangeByCampus(query)
  54. .OrderBy(x => x.No.Length).ThenBy(x => x.No)
  55. .ToList();
  56. }
  57. /// <summary>
  58. /// 查询全部校区信息CF_Campus
  59. /// </summary>
  60. /// <returns></returns>
  61. public List<CF_Campus> GetCampusList()
  62. {
  63. //校区信息
  64. Expression<Func<CF_Campus, bool>> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  65. var query = CampusDAL.CampusRepository.GetList(expCampus);
  66. return this.GetQueryByDataRangeByCampus(query)
  67. .OrderBy(x => x.No.Length).ThenBy(x => x.No)
  68. .ToList();
  69. }
  70. /// <summary>
  71. /// 查询全部校区信息CF_Campus(不考虑状态列)
  72. /// </summary>
  73. /// <returns></returns>
  74. public List<CF_Campus> GetCampusListWithoutDataRange()
  75. {
  76. //校区信息
  77. Expression<Func<CF_Campus, bool>> expCampus = (x => true);
  78. var query = CampusDAL.CampusRepository.GetList(expCampus);
  79. return query.OrderBy(x => x.No.Length).ThenBy(x => x.No)
  80. .ToList();
  81. }
  82. /// <summary>
  83. /// 查询对应的校区信息CampusView
  84. /// </summary>
  85. /// <param name="campusID"></param>
  86. /// <returns></returns>
  87. public CampusView GetCampusView(Guid? campusID)
  88. {
  89. try
  90. {
  91. var query = CampusDAL.GetCampusViewQueryable(x => x.CampusID == campusID)
  92. .SingleOrDefault();
  93. return query;
  94. }
  95. catch (Exception ex)
  96. {
  97. throw new Exception(ex.Message);
  98. }
  99. }
  100. /// <summary>
  101. /// 编辑(新增、修改,业务主键:校区代码或校区名称)
  102. /// </summary>
  103. /// <param name="campusView"></param>
  104. public void CampusEdit(CampusView campusView)
  105. {
  106. try
  107. {
  108. //查询数据库进行验证
  109. var campusVerification = CampusDAL.CampusRepository
  110. .GetList(x => x.CampusID != campusView.CampusID
  111. && (x.No == campusView.No
  112. || x.Name == campusView.Name))
  113. .FirstOrDefault();
  114. if (campusVerification == null)
  115. {
  116. //数据有误验证
  117. if (campusView.CampusID != Guid.Empty)
  118. {
  119. var campus = CampusDAL.CampusRepository
  120. .GetList(x => x.CampusID == campusView.CampusID)
  121. .SingleOrDefault();
  122. var campusProfile = CampusDAL.CampusProfileRepository
  123. .GetList(x => x.CampusID == campusView.CampusID)
  124. .SingleOrDefault();
  125. if (campus == null)
  126. {
  127. throw new Exception("数据有误,请核查");
  128. }
  129. else
  130. {
  131. //表示修改
  132. campus.UniversityID = campusView.UniversityID;
  133. campus.No = campusView.No;
  134. campus.Name = campusView.Name;
  135. campus.SimpleName = campusView.SimpleName;
  136. campus.EnglishName = campusView.EnglishName;
  137. campus.Remark = campusView.Remark;
  138. SetModifyStatus(campusView);
  139. //校区信息扩展表
  140. if (campusProfile == null)
  141. {
  142. //新增
  143. var newCampusProfile = new CF_CampusProfile();
  144. newCampusProfile.CampusID = campusView.CampusID;
  145. newCampusProfile.Generalsuper = campusView.Generalsuper;
  146. newCampusProfile.Recruitstudents = campusView.Recruitstudents;
  147. newCampusProfile.Placesuper = campusView.Placesuper;
  148. newCampusProfile.Teachingsuper = campusView.Teachingsuper;
  149. newCampusProfile.Studentcharge = campusView.Studentcharge;
  150. newCampusProfile.ZIPCode = campusView.ZIPCode;
  151. newCampusProfile.Officephone = campusView.Officephone;
  152. newCampusProfile.FAX = campusView.FAX;
  153. newCampusProfile.Email = campusView.Email;
  154. newCampusProfile.Evolution = campusView.Evolution;
  155. SetNewStatus(newCampusProfile);
  156. UnitOfWork.Add(newCampusProfile);
  157. }
  158. else
  159. {
  160. //修改
  161. campusProfile.Generalsuper = campusView.Generalsuper;
  162. campusProfile.Recruitstudents = campusView.Recruitstudents;
  163. campusProfile.Placesuper = campusView.Placesuper;
  164. campusProfile.Teachingsuper = campusView.Teachingsuper;
  165. campusProfile.Studentcharge = campusView.Studentcharge;
  166. campusProfile.ZIPCode = campusView.ZIPCode;
  167. campusProfile.Officephone = campusView.Officephone;
  168. campusProfile.FAX = campusView.FAX;
  169. campusProfile.Email = campusView.Email;
  170. campusProfile.Evolution = campusView.Evolution;
  171. SetModifyStatus(campusProfile);
  172. }
  173. }
  174. }
  175. else
  176. {
  177. //表示新增(CF_Campus主表)
  178. CF_Campus campus = new CF_Campus();
  179. campus.CampusID = Guid.NewGuid();
  180. campus.UniversityID = campusView.UniversityID;
  181. campus.No = campusView.No;
  182. campus.Name = campusView.Name;
  183. campus.SimpleName = campusView.SimpleName;
  184. campus.EnglishName = campusView.EnglishName;
  185. campus.Remark = campusView.Remark;
  186. SetNewStatus(campus);
  187. UnitOfWork.Add(campus);
  188. //表示新增(CF_CampusProfile扩展表)
  189. CF_CampusProfile campusProfile = new CF_CampusProfile();
  190. campusProfile.CampusID = campus.CampusID;
  191. campusProfile.Generalsuper = campusView.Generalsuper;
  192. campusProfile.Recruitstudents = campusView.Recruitstudents;
  193. campusProfile.Placesuper = campusView.Placesuper;
  194. campusProfile.Teachingsuper = campusView.Teachingsuper;
  195. campusProfile.Studentcharge = campusView.Studentcharge;
  196. campusProfile.ZIPCode = campusView.ZIPCode;
  197. campusProfile.Officephone = campusView.Officephone;
  198. campusProfile.FAX = campusView.FAX;
  199. campusProfile.Email = campusView.Email;
  200. campusProfile.Evolution = campusView.Evolution;
  201. SetNewStatus(campusProfile);
  202. UnitOfWork.Add(campusProfile);
  203. }
  204. }
  205. else
  206. {
  207. throw new Exception("已存在相同的" + RSL.Get("CampusCode") + "或" + RSL.Get("CampusName") + ",请核查");
  208. }
  209. //事务提交
  210. UnitOfWork.Commit();
  211. }
  212. catch (Exception ex)
  213. {
  214. throw new Exception(ex.Message);
  215. }
  216. }
  217. /// <summary>
  218. /// 删除
  219. /// </summary>
  220. /// <param name="campusIDList"></param>
  221. /// <returns></returns>
  222. public bool CampusDelete(List<Guid?> campusIDList)
  223. {
  224. try
  225. {
  226. UnitOfWork.Delete<CF_Campus>(x => campusIDList.Contains(x.CampusID));
  227. UnitOfWork.Commit();
  228. return true;
  229. }
  230. catch (Exception)
  231. {
  232. throw;
  233. }
  234. }
  235. }
  236. }