public List <ActivityFeedOutput> GetActivityFeed(IProviderAgencyOwner ao, ActivityFeedFilters filters) { var retVal = new List <ActivityFeedOutput>(); Task <List <LeadNotification> > leadNotifications = null; Task <List <ContractNotification> > contractNotifications = null; Task <List <CandidateNotification> > candidateNotifications = null; Task <List <ProposalNotification> > proposalNotifications = null; Task <List <ProjectNotification> > projectNotifications = null; using (var context = new AppDbContext(DbContextOptions)) { if (filters.Type.Contains(NotificationType.Lead)) { var query = context.LeadNotifications .Where(x => x.UserId == ao.CustomerId && x.OrganizationId == ao.OrganizationId && x.Created > filters.MaxDate); if (filters.LeadId.HasValue) { query = query.Where(x => x.LeadId == filters.LeadId.Value); } leadNotifications = query.ToListAsync(); } if (filters.Type.Contains(NotificationType.Candidate)) { var query = context.CandidateNotifications .Where(x => x.UserId == ao.CustomerId && x.OrganizationId == ao.OrganizationId && x.Created > filters.MaxDate); if (filters.CandidateId.HasValue) { query = query.Where(x => x.CandidateId == filters.CandidateId.Value); } candidateNotifications = query.ToListAsync(); } if (filters.Type.Contains(NotificationType.Contract)) { var query = context.ContractNotifications .Where(x => x.UserId == ao.CustomerId && x.OrganizationId == ao.OrganizationId && x.Created > filters.MaxDate); if (filters.ContractId.HasValue) { query = query.Where(x => x.ContractId == filters.ContractId.Value); } contractNotifications = query.ToListAsync(); } if (filters.Type.Contains(NotificationType.Proposal)) { var query = context.ProposalNotifications .Where(x => x.UserId == ao.CustomerId && x.OrganizationId == ao.OrganizationId && x.Created > filters.MaxDate); if (filters.ProposalId.HasValue) { query = query.Where(x => x.Id == filters.ProposalId.Value); } else if (filters.ProjectId.HasValue) { { query = query.Where(x => x.Id == filters.ProjectId.Value); } } proposalNotifications = query.ToListAsync(); } if (filters.Type.Contains(NotificationType.Project)) { var query = context.ProjectNotifications .Where(x => x.UserId == ao.CustomerId && x.OrganizationId == ao.OrganizationId && x.Created > filters.MaxDate); if (filters.ProjectId.HasValue) { query = query.Where(x => x.Id == filters.ProjectId.Value); } projectNotifications = query.ToListAsync(); } Task.WaitAll(); if (filters.Type.Contains(NotificationType.Lead)) { foreach (var item in leadNotifications.Result) { retVal.Add(new ActivityFeedOutput() { Url = item.Url, Message = item.Message, Created = item.Created }); } } if (filters.Type.Contains(NotificationType.Contract)) { foreach (var item in contractNotifications.Result) { retVal.Add(new ActivityFeedOutput() { Url = item.Url, Message = item.Message, Created = item.Created }); } } if (filters.Type.Contains(NotificationType.Candidate)) { foreach (var item in candidateNotifications.Result) { retVal.Add(new ActivityFeedOutput() { Url = item.Url, Message = item.Message, Created = item.Created }); } } if (filters.Type.Contains(NotificationType.Proposal)) { foreach (var item in proposalNotifications.Result) { retVal.Add(new ActivityFeedOutput() { Url = item.Url, Message = item.Message, Created = item.Created }); } } if (filters.Type.Contains(NotificationType.Project)) { foreach (var item in projectNotifications.Result) { retVal.Add(new ActivityFeedOutput() { Url = item.Url, Message = item.Message, Created = item.Created }); } } } return(retVal.OrderByDescending(x => x.Created).ToList()); }
public async Task <ActionResult> GetActivityFeed([FromRoute] Guid organizationId, [FromQuery] ActivityFeedFilters filters) { if (filters.Type.Count == 0) { filters.Type.Add(NotificationType.Lead); filters.Type.Add(NotificationType.Candidate); filters.Type.Add(NotificationType.Contract); filters.Type.Add(NotificationType.Project); filters.Type.Add(NotificationType.Proposal); filters.Type.Add(NotificationType.Invoice); filters.Type.Add(NotificationType.TimeEntry); filters.Type.Add(NotificationType.Story); } var ao = _providerAgencyOwner.Value; var output = _feedService.GetActivityFeed(ao, filters); return(Ok(output)); }