ShareRecordServices.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using Bowin.Common.Linq.Entity;
  2. using EMIS.DataLogic.ProjectShareManage;
  3. using EMIS.Entities;
  4. using EMIS.ViewModel;
  5. using EMIS.ViewModel.ProjectShareManage;
  6. using System;
  7. using System.Collections.Generic;
  8. using Bowin.Common.Linq;
  9. using System.Linq;
  10. using System.Linq.Expressions;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using EMIS.DataLogic.SystemDAL;
  14. using EMIS.ViewModel.SystemView;
  15. namespace EMIS.CommonLogic.ProjectShareManage
  16. {
  17. public class ShareRecordServices : BaseServices, IShareRecordServices
  18. {
  19. public ShareRecordDAL shareRecordDAL { get; set; }
  20. public UserDAL UserDAL { get; set; }
  21. public AnnouncementDAL AnnouncementDAL { get; set; }
  22. public IGridResultSet<ShareRecordView> GetShareRecordViewGrid(ConfiguretView configuretView, DateTime? startTime, DateTime? endTime, string title, Guid? userID, int pageIndex, int pageSize)
  23. {
  24. Expression<Func<Sys_ShareRecord, bool>> exp = (x => true);
  25. if (startTime.HasValue)
  26. {
  27. exp = exp.And(x => x.DateTime >= startTime);
  28. }
  29. if (endTime.HasValue)
  30. {
  31. exp = exp.And(x => x.DateTime <= endTime);
  32. }
  33. if (userID.HasValue)
  34. {
  35. exp = exp.And(x => x.UserID == userID);
  36. }
  37. var query = shareRecordDAL.GetShareRecordView(exp);
  38. if (title != "" && title != null)
  39. {
  40. query.Where(x => x.Title.Contains(title));
  41. }
  42. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  43. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  44. return query.OrderBy(x => x.Title).ThenBy(x => x.ClassmajorID).ThenBy(x => x.UserID).ToGridResultSet<ShareRecordView>(pageIndex, pageSize);
  45. }
  46. public List<ShareRecordView> GetShareRecordViewList(ConfiguretView configuretView, DateTime? startTime, DateTime? endTime, string title, Guid? userID, List<Guid> idList = null)
  47. {
  48. Expression<Func<Sys_ShareRecord, bool>> exp = (x => true);
  49. if (startTime.HasValue)
  50. {
  51. exp = exp.And(x => x.DateTime >= startTime);
  52. }
  53. if (endTime.HasValue)
  54. {
  55. exp = exp.And(x => x.DateTime <= endTime);
  56. }
  57. if (userID.HasValue)
  58. {
  59. exp = exp.And(x => x.UserID == userID);
  60. }
  61. if (idList != null && idList.Count() > 0)
  62. {
  63. exp = exp.And(x => idList.Contains(x.ShareRecordID));
  64. }
  65. var query = shareRecordDAL.GetShareRecordView(exp);
  66. if (title != "" && title != null)
  67. {
  68. query.Where(x => x.Title.Contains(title));
  69. }
  70. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  71. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  72. return query.OrderBy(x => x.Title).ThenBy(x => x.ClassmajorID).ThenBy(x => x.UserID).ToList();
  73. }
  74. public void CheckAndRecordScore(Guid? announcementID, string loginID, string openID)
  75. {
  76. try
  77. {
  78. Sys_ShareRecord sys_ShareRecord = new Sys_ShareRecord();
  79. var user = UserDAL.GetStudentUserView(x => x.LoginID == loginID, y => true).FirstOrDefault();
  80. Expression<Func<Sys_ShareRecord, bool>> exp = (x => true);
  81. List<ShareRecordView> ShareRecordViewList = shareRecordDAL.GetShareRecordView(exp).ToList();
  82. List<AnnouncementTypeView> typeList = AnnouncementDAL.GetAnnouncementTypeView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).OrderBy(x => x.Name).ToList();
  83. var type = typeList.Where(x => x.No == "05").FirstOrDefault();
  84. var wechatSubscribe = shareRecordDAL.wechatSubscribeRepository.Entities.Where(x => x.UserID == user.UserID).FirstOrDefault();
  85. var announcement = shareRecordDAL.announcementRepository.Entities.Where(x => x.AnnouncementID == announcementID).FirstOrDefault();
  86. var ShareRecordView = ShareRecordViewList.Where(x => x.UserID == user.UserID && x.AnnouncementID == announcementID && x.OpenID == openID).FirstOrDefault();
  87. if (announcement.AnnouncementTypeID == type.AnnouncementTypeID && ShareRecordView == null && wechatSubscribe.OpenID != openID)
  88. {
  89. sys_ShareRecord.ShareRecordID = Guid.NewGuid();
  90. sys_ShareRecord.AnnouncementID = announcementID;
  91. sys_ShareRecord.UserID = user.UserID;
  92. sys_ShareRecord.OpenID = openID;
  93. sys_ShareRecord.RecordStatus = 1;
  94. sys_ShareRecord.DateTime = DateTime.Now;
  95. sys_ShareRecord.CreateTime = DateTime.Now;
  96. sys_ShareRecord.CreateUserID = user.UserID;
  97. sys_ShareRecord.ModifyTime = DateTime.Now;
  98. sys_ShareRecord.ModifyUserID = user.UserID;
  99. UnitOfWork.Add(sys_ShareRecord);
  100. }
  101. else
  102. {
  103. }
  104. UnitOfWork.Commit();
  105. }
  106. catch (Exception)
  107. {
  108. throw;
  109. }
  110. }
  111. }
  112. }