ClubCourseServices.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.ViewModel;
  8. using Bowin.Common.Linq;
  9. using EMIS.Entities;
  10. using EMIS.DataLogic.CultureplanManage.CourseMaterial;
  11. using EMIS.ViewModel.Cultureplan;
  12. using EMIS.ViewModel.CultureplanManage.CourseMaterial;
  13. namespace EMIS.CommonLogic.CultureplanManage.CourseMaterial
  14. {
  15. public class ClubCourseServices : BaseServices, IClubCourseServices
  16. {
  17. public ClubCourseDAL ClubCourseDAL { get; set; }
  18. /// <summary>
  19. /// 查询对应的俱乐部课程View
  20. /// </summary>
  21. /// <param name="configuretView"></param>
  22. /// <param name="courseLevelID"></param>
  23. /// <param name="courseScienceID"></param>
  24. /// <param name="classGroupingID"></param>
  25. /// <param name="isEnable"></param>
  26. /// <param name="pageIndex"></param>
  27. /// <param name="pageSize"></param>
  28. /// <returns></returns>
  29. public IGridResultSet<ClubCourseView> GetClubCourseViewGrid(ConfiguretView configuretView, int? courseLevelID, int? courseScienceID,
  30. Guid? classGroupingID, int? isEnable, int pageIndex, int pageSize)
  31. {
  32. //俱乐部课程
  33. Expression<Func<ER_ClubCourse, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  34. var query = ClubCourseDAL.GetClubCourseViewQueryable(exp);
  35. if (courseLevelID.HasValue)
  36. {
  37. query = query.Where(x => x.CourseLevelID == courseLevelID);
  38. }
  39. if (courseScienceID.HasValue)
  40. {
  41. query = query.Where(x => x.CourseScienceID == courseScienceID);
  42. }
  43. if (classGroupingID.HasValue)
  44. {
  45. query = query.Where(x => x.ClassGroupingID == classGroupingID);
  46. }
  47. if (isEnable.HasValue)
  48. {
  49. if (isEnable == 1)
  50. {
  51. query = query.Where(x => x.IsEnable == true);
  52. }
  53. if (isEnable == 0)
  54. {
  55. query = query.Where(x => x.IsEnable != true);
  56. }
  57. }
  58. //查询条件
  59. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  60. {
  61. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  62. }
  63. return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  64. .ToGridResultSet<ClubCourseView>(pageIndex, pageSize);
  65. }
  66. /// <summary>
  67. /// 查询对应的俱乐部课程List
  68. /// </summary>
  69. /// <param name="configuretView"></param>
  70. /// <param name="courseLevelID"></param>
  71. /// <param name="courseScienceID"></param>
  72. /// <param name="classGroupingID"></param>
  73. /// <param name="isEnable"></param>
  74. /// <returns></returns>
  75. public List<ClubCourseView> GetClubCourseViewList(ConfiguretView configuretView, int? courseLevelID, int? courseScienceID,
  76. Guid? classGroupingID, int? isEnable)
  77. {
  78. //俱乐部课程
  79. Expression<Func<ER_ClubCourse, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  80. var query = ClubCourseDAL.GetClubCourseViewQueryable(exp);
  81. if (courseLevelID.HasValue)
  82. {
  83. query = query.Where(x => x.CourseLevelID == courseLevelID);
  84. }
  85. if (courseScienceID.HasValue)
  86. {
  87. query = query.Where(x => x.CourseScienceID == courseScienceID);
  88. }
  89. if (classGroupingID.HasValue)
  90. {
  91. query = query.Where(x => x.ClassGroupingID == classGroupingID);
  92. }
  93. if (isEnable.HasValue)
  94. {
  95. if (isEnable == 1)
  96. {
  97. query = query.Where(x => x.IsEnable == true);
  98. }
  99. if (isEnable == 0)
  100. {
  101. query = query.Where(x => x.IsEnable != true);
  102. }
  103. }
  104. //查询条件
  105. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  106. {
  107. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  108. }
  109. return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ToList();
  110. }
  111. /// <summary>
  112. /// 查询对应的课程信息View(课程信息表左连俱乐部课程表,排除对应的俱乐部课程信息)
  113. /// </summary>
  114. /// <param name="configuretView"></param>
  115. /// <param name="courseLevelID"></param>
  116. /// <param name="courseScienceID"></param>
  117. /// <param name="isEnable"></param>
  118. /// <param name="pageIndex"></param>
  119. /// <param name="pageSize"></param>
  120. /// <returns></returns>
  121. public IGridResultSet<CoursematerialView> GetCourseNoClubViewGrid(ConfiguretView configuretView, int? courseLevelID,
  122. int? courseScienceID, int? isEnable, int pageIndex, int pageSize)
  123. {
  124. //课程信息
  125. Expression<Func<EM_Coursematerial, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  126. if (courseLevelID.HasValue)
  127. {
  128. //课程级别
  129. exp = exp.And(x => x.CourseLevelID == courseLevelID);
  130. }
  131. if (courseScienceID.HasValue)
  132. {
  133. //课程科类
  134. exp = exp.And(x => x.CourseScienceID == courseScienceID);
  135. }
  136. if (isEnable.HasValue)
  137. {
  138. if (isEnable == 1)
  139. {
  140. exp = exp.And(x => x.IsEnable == true);
  141. }
  142. if (isEnable == 0)
  143. {
  144. exp = exp.And(x => x.IsEnable != true);
  145. }
  146. }
  147. var query = ClubCourseDAL.GetCourseNoClubViewQueryable(exp);
  148. //查询条件
  149. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  150. {
  151. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  152. }
  153. return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  154. .ToGridResultSet<CoursematerialView>(pageIndex, pageSize);
  155. }
  156. /// <summary>
  157. /// 查询对应的课程信息List(课程信息表左连俱乐部课程表,排除对应的俱乐部课程信息)
  158. /// </summary>
  159. /// <param name="configuretView"></param>
  160. /// <param name="courseLevelID"></param>
  161. /// <param name="courseScienceID"></param>
  162. /// <param name="isEnable"></param>
  163. /// <returns></returns>
  164. public List<CoursematerialView> GetCourseNoClubViewList(ConfiguretView configuretView, int? courseLevelID, int? courseScienceID, int? isEnable)
  165. {
  166. //课程信息
  167. Expression<Func<EM_Coursematerial, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  168. if (courseLevelID.HasValue)
  169. {
  170. //课程级别
  171. exp = exp.And(x => x.CourseLevelID == courseLevelID);
  172. }
  173. if (courseScienceID.HasValue)
  174. {
  175. //课程科类
  176. exp = exp.And(x => x.CourseScienceID == courseScienceID);
  177. }
  178. if (isEnable.HasValue)
  179. {
  180. if (isEnable == 1)
  181. {
  182. exp = exp.And(x => x.IsEnable == true);
  183. }
  184. if (isEnable == 0)
  185. {
  186. exp = exp.And(x => x.IsEnable != true);
  187. }
  188. }
  189. var query = ClubCourseDAL.GetCourseNoClubViewQueryable(exp);
  190. //查询条件
  191. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  192. {
  193. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  194. }
  195. return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ToList();
  196. }
  197. /// <summary>
  198. /// 根据俱乐部课程ID查询对应的俱乐部课程信息ClubCourseView
  199. /// </summary>
  200. /// <param name="ClubCourseID"></param>
  201. /// <returns></returns>
  202. public ClubCourseView GetClubCourseView(Guid? ClubCourseID)
  203. {
  204. try
  205. {
  206. var query = ClubCourseDAL.GetClubCourseViewQueryable(x => x.ClubCourseID == ClubCourseID)
  207. .SingleOrDefault();
  208. return query;
  209. }
  210. catch (Exception ex)
  211. {
  212. throw new Exception(ex.Message);
  213. }
  214. }
  215. /// <summary>
  216. /// 批量新增
  217. /// </summary>
  218. /// <param name="clubCourseView"></param>
  219. /// <param name="courseNoClubViewList"></param>
  220. /// <returns></returns>
  221. public string ClubCourseBatchAdd(ClubCourseView clubCourseView, List<CoursematerialView> courseNoClubViewList)
  222. {
  223. try
  224. {
  225. //俱乐部课程信息List
  226. var clubCourseList = ClubCourseDAL.ClubCourseRepository
  227. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  228. int success = 0; //成功
  229. int fail = 0; //失败
  230. string tipMessage = null; //提示消息
  231. List<ER_ClubCourse> clubCourseInList = new List<ER_ClubCourse>();
  232. foreach (var courseNoClubView in courseNoClubViewList)
  233. {
  234. //查询数据库进行验证
  235. var clubCourseVerification = clubCourseList
  236. .Where(x => x.CoursematerialID == courseNoClubView.CoursematerialID)
  237. .SingleOrDefault();
  238. if (clubCourseVerification == null)
  239. {
  240. //表示不存在对应的俱乐部课程(新增)
  241. ER_ClubCourse clubCourse = new ER_ClubCourse();
  242. clubCourse.ClubCourseID = Guid.NewGuid();
  243. clubCourse.CoursematerialID = courseNoClubView.CoursematerialID;
  244. SetNewStatus(clubCourse);
  245. clubCourseInList.Add(clubCourse);
  246. success++;
  247. }
  248. else
  249. {
  250. //表示已存在相同的俱乐部课程
  251. fail++;
  252. }
  253. }
  254. //批量插入
  255. UnitOfWork.BulkInsert<ER_ClubCourse>(clubCourseInList);
  256. if (success > 0 && fail <= 0)
  257. {
  258. tipMessage = success + "条";
  259. }
  260. else
  261. {
  262. tipMessage = success + "条," + fail + "条失败,原因:已存在相同的俱乐部课程,请检查";
  263. }
  264. return tipMessage;
  265. }
  266. catch (Exception ex)
  267. {
  268. throw new Exception(ex.Message);
  269. }
  270. }
  271. /// <summary>
  272. /// 删除
  273. /// </summary>
  274. /// <param name="clubCourseIDList"></param>
  275. /// <returns></returns>
  276. public bool ClubCourseDelete(List<Guid?> clubCourseIDList)
  277. {
  278. try
  279. {
  280. UnitOfWork.Delete<ER_ClubCourse>(x => clubCourseIDList.Contains(x.ClubCourseID));
  281. UnitOfWork.Commit();
  282. return true;
  283. }
  284. catch (Exception ex)
  285. {
  286. throw new Exception(ex.Message);
  287. }
  288. }
  289. }
  290. }