using Bowin.Common.Linq.Entity; using EMIS.DataLogic.ProjectShareManage; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.ProjectShareManage; using System; using System.Collections.Generic; using Bowin.Common.Linq; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using EMIS.DataLogic.SystemDAL; using EMIS.ViewModel.SystemView; namespace EMIS.CommonLogic.ProjectShareManage { public class ShareRecordServices : BaseServices, IShareRecordServices { public ShareRecordDAL shareRecordDAL { get; set; } public UserDAL UserDAL { get; set; } public AnnouncementDAL AnnouncementDAL { get; set; } public IGridResultSet GetShareRecordViewGrid(ConfiguretView configuretView, DateTime? startTime, DateTime? endTime, string title, Guid? userID, int pageIndex, int pageSize) { Expression> exp = (x => true); if (startTime.HasValue) { exp = exp.And(x => x.DateTime >= startTime); } if (endTime.HasValue) { exp = exp.And(x => x.DateTime <= endTime); } if (userID.HasValue) { exp = exp.And(x => x.UserID == userID); } var query = shareRecordDAL.GetShareRecordView(exp); if (title != "" && title != null) { query.Where(x => x.Title.Contains(title)); } if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return query.OrderBy(x => x.Title).ThenBy(x => x.ClassmajorID).ThenBy(x => x.UserID).ToGridResultSet(pageIndex, pageSize); } public List GetShareRecordViewList(ConfiguretView configuretView, DateTime? startTime, DateTime? endTime, string title, Guid? userID, List idList = null) { Expression> exp = (x => true); if (startTime.HasValue) { exp = exp.And(x => x.DateTime >= startTime); } if (endTime.HasValue) { exp = exp.And(x => x.DateTime <= endTime); } if (userID.HasValue) { exp = exp.And(x => x.UserID == userID); } if (idList != null && idList.Count() > 0) { exp = exp.And(x => idList.Contains(x.ShareRecordID)); } var query = shareRecordDAL.GetShareRecordView(exp); if (title != "" && title != null) { query.Where(x => x.Title.Contains(title)); } if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return query.OrderBy(x => x.Title).ThenBy(x => x.ClassmajorID).ThenBy(x => x.UserID).ToList(); } public void CheckAndRecordScore(Guid? announcementID, string loginID, string openID) { try { Sys_ShareRecord sys_ShareRecord = new Sys_ShareRecord(); var user = UserDAL.GetStudentUserView(x => x.LoginID == loginID, y => true).FirstOrDefault(); Expression> exp = (x => true); List ShareRecordViewList = shareRecordDAL.GetShareRecordView(exp).ToList(); List typeList = AnnouncementDAL.GetAnnouncementTypeView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).OrderBy(x => x.Name).ToList(); var type = typeList.Where(x => x.No == "05").FirstOrDefault(); var wechatSubscribe = shareRecordDAL.wechatSubscribeRepository.Entities.Where(x => x.UserID == user.UserID).FirstOrDefault(); var announcement = shareRecordDAL.announcementRepository.Entities.Where(x => x.AnnouncementID == announcementID).FirstOrDefault(); var ShareRecordView = ShareRecordViewList.Where(x => x.UserID == user.UserID && x.AnnouncementID == announcementID && x.OpenID == openID).FirstOrDefault(); if (announcement.AnnouncementTypeID == type.AnnouncementTypeID && ShareRecordView == null && wechatSubscribe.OpenID != openID) { sys_ShareRecord.ShareRecordID = Guid.NewGuid(); sys_ShareRecord.AnnouncementID = announcementID; sys_ShareRecord.UserID = user.UserID; sys_ShareRecord.OpenID = openID; sys_ShareRecord.RecordStatus = 1; sys_ShareRecord.DateTime = DateTime.Now; sys_ShareRecord.CreateTime = DateTime.Now; sys_ShareRecord.CreateUserID = user.UserID; sys_ShareRecord.ModifyTime = DateTime.Now; sys_ShareRecord.ModifyUserID = user.UserID; UnitOfWork.Add(sys_ShareRecord); } else { } UnitOfWork.Commit(); } catch (Exception) { throw; } } } }