public static List <NotificationDTO> GetNotificationList(NotificationSearchCondition condition, out int totalSize) { var context = PrepareDb(); if (condition == null) { condition = new NotificationSearchCondition(); } var entity = BaseWFEntity.GetWorkflowEntity(condition.ProjectId, condition.FlowCode); Guid? entityId = null; string souceCode = ""; string tableName = ""; if (entity != null) { souceCode = entity.WorkflowCode.Split('_')[0]; entityId = entity.EntityId; } int pageIndex = condition.PageIndex; int pageSize = condition.PageSize; totalSize = 0; var data = (from N in context.Notification join M in context.NotificationMessage on N.ContentId equals M.Id join E in context.Employee on N.SenderCode equals E.Code join R in context.Employee on N.ReceiverCode equals R.Code into TEMPEM from tem in TEMPEM.DefaultIfEmpty() where (string.IsNullOrEmpty(condition.Title) || M.MessageContent.Contains(condition.Title)) && N.ProjectId == condition.ProjectId && N.FlowCode == condition.FlowCode && (string.IsNullOrEmpty(condition.SenderCode) || N.SenderCode == condition.SenderCode) orderby N.CreateTime descending select new NotificationDTO { Id = N.Id, RefId = N.RefId, ProjectId = N.ProjectId, SenderCode = N.SenderCode, ReceiverCode = N.ReceiverCode, CreateTime = N.CreateTime, LastUpdateTime = N.LastUpdateTime, CreateUserAccount = N.CreateUserAccount, IsSendEmail = N.IsSendEmail, HasRead = N.HasRead, FlowCode = N.FlowCode, PositionENUS = E.PositionENUS, PositionZHCN = E.PositionZHCN, SenderENUS = E.NameENUS, SenderZHCN = E.NameZHCN, ReceiverENUS = tem.NameENUS, ReceiverZHCN = tem.NameZHCN, Message = M.MessageContent } ).Union( from PC in context.ProjectComment where PC.Status == ProjectCommentStatus.Submit && entityId != null && PC.RefTableId == entityId && PC.SourceCode == souceCode && (string.IsNullOrEmpty(condition.Title) || PC.Content.Contains(condition.Title)) && (string.IsNullOrEmpty(condition.SenderCode) || PC.CreateUserAccount == condition.SenderCode) orderby PC.CreateTime descending select new NotificationDTO { Id = PC.Num, RefId = PC.RefTableId, ProjectId = condition.ProjectId, SenderCode = PC.CreateUserAccount, ReceiverCode = "", CreateTime = PC.CreateTime, LastUpdateTime = null, CreateUserAccount = PC.CreateUserAccount, IsSendEmail = false, HasRead = true, FlowCode = condition.FlowCode, PositionENUS = "", PositionZHCN = "", SenderENUS = string.IsNullOrEmpty(PC.CreateUserNameENUS)?PC.UserNameENUS:PC.CreateUserNameENUS, SenderZHCN = string.IsNullOrEmpty(PC.CreateUserNameZHCN) ? PC.UserNameZHCN : PC.CreateUserNameZHCN, ReceiverENUS = "", ReceiverZHCN = "", Message = PC.Content } ); IQueryable <NotificationDTO> filterData = null; if (condition.CreateDate.HasValue && condition.EndDate.HasValue) { var endDate = condition.EndDate.Value.AddDays(1); filterData = data.Where( e => e.CreateTime >= condition.CreateDate.Value && e.CreateTime <= endDate); } else { filterData = data; } totalSize = filterData.Count(); var result = filterData .OrderByDescending(e => e.CreateTime) .Skip(pageSize * (pageIndex - 1)) .Take(pageSize) .ToList() .Select(e => new NotificationDTO() { Id = e.Id, RefId = e.RefId, ProjectId = e.ProjectId, SenderCode = e.SenderCode, ReceiverCode = e.ReceiverCode, CreateTime = e.CreateTime, LastUpdateTime = e.LastUpdateTime, CreateUserAccount = e.CreateUserAccount, IsSendEmail = e.IsSendEmail, HasRead = e.HasRead, FlowCode = e.FlowCode, PositionENUS = e.PositionENUS, PositionZHCN = e.PositionZHCN, SenderZHCN = e.SenderZHCN, SenderENUS = e.SenderENUS, ReceiverENUS = e.ReceiverENUS, ReceiverZHCN = e.ReceiverZHCN, Message = e.Message }).ToList(); return(result); }
public List <Notification> GetNotificationByProjectId(string projectId, string flowCode) { var context = GetDb(); var listNotification = (from N in context.Notification join M in context.NotificationMessage on N.ContentId equals M.Id join E in context.Employee on N.SenderCode equals E.Code join EM in context.Employee on N.ReceiverCode equals EM.Code into TEMPEM from tem in TEMPEM.DefaultIfEmpty() where N.ProjectId == projectId && N.FlowCode == flowCode orderby N.CreateTime descending select new { Id = N.Id, RefId = N.RefId, ProjectId = N.ProjectId, SenderCode = N.SenderCode, ReceiverCode = N.ReceiverCode, CreateTime = N.CreateTime, LastUpdateTime = N.LastUpdateTime, CreateUserAccount = N.CreateUserAccount, IsSendEmail = N.IsSendEmail, HasRead = N.HasRead, FlowCode = N.FlowCode, PositionENUS = E.PositionENUS, PositionZHCN = E.PositionZHCN, SenderNameENUS = E.NameENUS, SenderNameZHCN = E.NameZHCN, ReceiverNameENUS = tem.NameENUS, ReceiverNameZHCN = tem.NameZHCN, Message = M.MessageContent, ContentId = N.ContentId, Title = N.Title }).ToList().Select(e => new Notification() { Id = e.Id, RefId = e.RefId, ProjectId = e.ProjectId, SenderCode = e.SenderCode, ReceiverCode = e.ReceiverCode, CreateTime = e.CreateTime, LastUpdateTime = e.LastUpdateTime, CreateUserAccount = e.CreateUserAccount, IsSendEmail = e.IsSendEmail, HasRead = e.HasRead, FlowCode = e.FlowCode, PositionENUS = e.PositionENUS, PositionZHCN = e.PositionZHCN, SenderZHCN = e.SenderNameZHCN, SenderENUS = e.SenderNameENUS, ReceiverZHCN = e.ReceiverNameZHCN, ReceiverENUS = e.ReceiverNameENUS, Message = e.Message, ContentId = e.ContentId, Title = e.Title }).ToList(); Read(listNotification); Update(listNotification.ToArray()); return(listNotification); }