ActivitieServices.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.CalendarManage;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel;
  9. using System.Linq.Expressions;
  10. using EMIS.ViewModel.CalendarManage;
  11. namespace EMIS.CommonLogic.CalendarManage
  12. {
  13. public class ActivitieServices : BaseServices, IActivitieServices
  14. {
  15. public ActivitieDAL activitieDAL { get; set; }
  16. /// <summary>
  17. /// 查询固定活动信息
  18. /// </summary>
  19. /// <param name="configuretView">查询条件实体</param>
  20. /// <param name="activitiesType">活动类型</param>
  21. /// <param name="timesSegment">时间段</param>
  22. /// <param name="pageIndex">页码</param>
  23. /// <param name="pageSize">显示页数</param>
  24. /// <returns></returns>
  25. public IGridResultSet<ActivitieView> GetActivitieViewGrid(ConfiguretView configuretView, int? activitiesType, int? timesSegment, int pageIndex, int pageSize)
  26. {
  27. var query = activitieDAL.GetActivitiesQueryable(x => true);
  28. if (activitiesType.HasValue && activitiesType!=-1)
  29. query = query.Where(x => x.ActivitiesType == activitiesType);
  30. if (timesSegment.HasValue && timesSegment != -1)
  31. query = query.Where(x => x.TimesSegment == timesSegment);
  32. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  33. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue)
  34. .OrderBy(x => x.ActivitiesTimeMonth).ThenBy(x => x.ActivitiesTimeDay).ThenBy(x => x.TimesSegment).ToGridResultSet<ActivitieView>(pageIndex, pageSize);
  35. return query.OrderBy(x => x.ActivitiesTimeMonth).ThenBy(x => x.ActivitiesTimeDay).ThenBy(x => x.TimesSegment).ToGridResultSet<ActivitieView>(pageIndex, pageSize);
  36. }
  37. /// <summary>
  38. /// 查询固定活动信息
  39. /// </summary>
  40. /// <param name="configuretView">查询条件实体</param>
  41. /// <param name="activitiesType">活动类型</param>
  42. /// <param name="timesSegment">时间段</param>
  43. /// <returns></returns>
  44. public List<ActivitieView> GetActivitieViewList(ConfiguretView configuretView, int? activitiesType, int? timesSegment)
  45. {
  46. var query = activitieDAL.GetActivitiesQueryable(x => true);
  47. if (activitiesType.HasValue && activitiesType != -1)
  48. query = query.Where(x => x.ActivitiesType == activitiesType);
  49. if (timesSegment.HasValue && timesSegment != -1)
  50. query = query.Where(x => x.TimesSegment == timesSegment);
  51. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  52. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue)
  53. .OrderBy(x => x.ActivitiesTimeMonth).ThenBy(x => x.ActivitiesTimeDay).ThenBy(x => x.TimesSegment).ToList();
  54. return query.OrderBy(x => x.ActivitiesTimeMonth).ThenBy(x => x.ActivitiesTimeDay).ThenBy(x => x.TimesSegment).ToList();
  55. }
  56. /// <summary>
  57. /// 获取固定活动信息
  58. /// </summary>
  59. /// <param name="activitiesID">主键ID</param>
  60. /// <returns></returns>
  61. public CF_ActivitiesSets GetActivitie(Guid? activitiesID)
  62. {
  63. //查询条件
  64. Expression<Func<CF_ActivitiesSets, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  65. expression = (x => x.ActivitiesID == activitiesID);
  66. return activitieDAL.activitiesSetsRepository.GetSingle(expression);
  67. }
  68. /// <summary>
  69. /// 获取固定活动信息
  70. /// </summary>
  71. /// <param name="Name">活动名称</param>
  72. /// <returns></returns>
  73. public CF_ActivitiesSets GetActivitie(string Name)
  74. {
  75. //查询条件
  76. Expression<Func<CF_ActivitiesSets, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  77. expression = (x => x.Name == Name);
  78. return activitieDAL.activitiesSetsRepository.GetSingle(expression);
  79. }
  80. /// <summary>
  81. /// 获取固定活动信息
  82. /// </summary>
  83. /// <param name="activitiesID">主键ID</param>
  84. /// <returns></returns>
  85. public ActivitieView GetActivitieView(Guid? activitiesID)
  86. {
  87. ActivitieView activitieView = new ActivitieView();
  88. if (activitiesID.HasValue)
  89. activitieView = activitieDAL.GetActivitiesQueryable(x => true).Where(x => x.ActivitiesID == activitiesID).FirstOrDefault();
  90. return activitieView;
  91. }
  92. /// <summary>
  93. /// 添加
  94. /// </summary>
  95. /// <param name="activitiesSets">实体</param>
  96. /// <returns></returns>
  97. public bool ActivitiesAdd(ActivitieView activitieView)
  98. {
  99. try
  100. {
  101. if (this.activitieDAL.activitiesSetsRepository
  102. .GetList(x => x.Name == activitieView.Name&&x.ActivitiesTimeMonth==activitieView.ActivitiesTimeMonth
  103. && x.ActivitiesTimeDay == activitieView.ActivitiesTimeDay && x.TimesSegment == activitieView.TimesSegment).Count() > 0)
  104. {
  105. throw new Exception("已存在相同的数据,请重新输入!");
  106. }
  107. CF_ActivitiesSets activitiesSets = new CF_ActivitiesSets();
  108. activitiesSets.ActivitiesID = Guid.NewGuid();
  109. activitiesSets.Name = activitieView.Name;
  110. activitiesSets.ActivitiesTimeMonth = activitieView.ActivitiesTimeMonth.Value;
  111. activitiesSets.ActivitiesTimeDay = activitieView.ActivitiesTimeDay.Value;
  112. activitiesSets.TimesSegment = activitieView.TimesSegment.Value;
  113. activitiesSets.ActivitiesContent = activitieView.ActivitiesContent;
  114. activitiesSets.ActivitiesType = activitieView.ActivitiesType;
  115. this.SetNewStatus(activitiesSets);
  116. UnitOfWork.Add(activitiesSets);
  117. UnitOfWork.Commit();
  118. return true;
  119. }
  120. catch (Exception)
  121. {
  122. throw;
  123. }
  124. }
  125. /// <summary>
  126. /// 修改
  127. /// </summary>
  128. /// <param name="activitiesSets">实体</param>
  129. /// <returns></returns>
  130. public bool ActivitiesUpdate(ActivitieView activitieView)
  131. {
  132. try
  133. {
  134. CF_ActivitiesSets activitiesSets = GetActivitie(activitieView.ActivitiesID);
  135. if (activitiesSets == null)
  136. {
  137. throw new Exception("保存失败,未能找到相对应的数据!");
  138. }
  139. activitiesSets.Name = activitieView.Name;
  140. activitiesSets.ActivitiesTimeMonth = activitieView.ActivitiesTimeMonth.Value;
  141. activitiesSets.ActivitiesTimeDay = activitieView.ActivitiesTimeDay.Value;
  142. activitiesSets.TimesSegment = activitieView.TimesSegment.Value;
  143. activitiesSets.ActivitiesContent = activitieView.ActivitiesContent;
  144. activitiesSets.ActivitiesType = activitieView.ActivitiesType;
  145. this.SetModifyStatus(activitiesSets);
  146. UnitOfWork.Commit();
  147. return true;
  148. }
  149. catch (Exception)
  150. {
  151. throw;
  152. }
  153. }
  154. /// <summary>
  155. /// 删除
  156. /// </summary>
  157. /// <param name="activitiesIDs"></param>
  158. /// <returns></returns>
  159. public bool ActivitiesDelete(List<Guid> activitiesIDs)
  160. {
  161. try
  162. {
  163. UnitOfWork.Delete<CF_ActivitiesSets>(x => activitiesIDs.Contains(x.ActivitiesID));
  164. UnitOfWork.Commit();
  165. return true;
  166. }
  167. catch (Exception)
  168. {
  169. throw;
  170. }
  171. }
  172. }
  173. }