internal async Task <IEnumerable <EmailNotificationMessage <CostNotificationObject> > > Build(dataAccess.Entity.Cost cost, CostNotificationUsers costUsers, CostStageRevision costStageRevision, DateTime timestamp) { var notifications = new List <EmailNotificationMessage <CostNotificationObject> >(); var approvals = _approvalService.GetApprovalsByCostStageRevisionId(costStageRevision.Id).Result; const string actionType = core.Constants.EmailNotificationActionType.TechnicalApproverAssigned; if (approvals == null) { //No approvals set return(notifications); } var costOwner = costUsers.CostOwner; var technicalApprovals = approvals.Where(a => a.Type == ApprovalType.IPM).ToArray(); foreach (var technicalApproval in technicalApprovals) { foreach (var approvalMember in technicalApproval.ApprovalMembers) { //Send notifications to Technical Approver var approvalCostUser = approvalMember.CostUser; var technicalApproverNotification = new EmailNotificationMessage <CostNotificationObject>(actionType, approvalCostUser.GdamUserId); AddSharedTo(technicalApproverNotification); MapEmailNotificationObject(technicalApproverNotification.Object, cost, costOwner, approvalCostUser); PopulateOtherFields(technicalApproverNotification, core.Constants.EmailNotificationParents.TechnicalApprover, timestamp, cost.Id, costStageRevision.Id, approvalCostUser); await PopulateMetadata(technicalApproverNotification.Object, cost.Id); notifications.Add(technicalApproverNotification); //Insurance User if (ShouldNotifyInsuranceUsers(costUsers)) { var insuranceUserNotification = new EmailNotificationMessage <CostNotificationObject>(actionType, costUsers.InsuranceUsers); AddSharedTo(insuranceUserNotification); MapEmailNotificationObject(insuranceUserNotification.Object, cost, costOwner, approvalCostUser); PopulateOtherFields(insuranceUserNotification, core.Constants.EmailNotificationParents.InsuranceUser, timestamp, cost.Id, costStageRevision.Id, approvalCostUser); await PopulateMetadata(insuranceUserNotification.Object, cost.Id); notifications.Add(insuranceUserNotification); } } } await AddFinanceManagerNotification(actionType, cost, costUsers, costStageRevision, timestamp, notifications); return(notifications); }
internal async Task <IEnumerable <EmailNotificationMessage <CostNotificationObject> > > Build(Cost cost, CostNotificationUsers costUsers, CostStageRevision costStageRevision, DateTime timestamp) { var notifications = new List <EmailNotificationMessage <CostNotificationObject> >(); //Build PendingBrandApproval notifications var approvals = _approvalService.GetApprovalsByCostStageRevisionId(costStageRevision.Id).Result; if (approvals != null) { await BuildPendingBrandApprovalNotification(notifications, approvals, cost, costUsers, costStageRevision, timestamp); } return(notifications); }
internal async Task <IEnumerable <EmailNotificationMessage <CostNotificationObject> > > Build(dataAccess.Entity.Cost cost, CostNotificationUsers costUsers, CostStageRevision costStageRevision, DateTime timestamp) { var notifications = new List <EmailNotificationMessage <CostNotificationObject> >(); var approvals = await _approvalService.GetApprovalsByCostStageRevisionId(costStageRevision.Id); if (approvals == null) { //No approvals set return(notifications); } await BuildPendingTechnicalApprovalNotification(notifications, approvals, cost, costUsers, costUsers.CostOwner, costStageRevision, timestamp); return(notifications); }
internal async Task <IEnumerable <EmailNotificationMessage <CostNotificationObject> > > BuildAsync(Cost cost, CostNotificationUsers costUsers, CostStageRevision costStageRevision, DateTime timestamp) { var notifications = new List <EmailNotificationMessage <CostNotificationObject> >(); //Cost Owner var costOwner = costUsers.CostOwner; var actionType = Constants.EmailNotificationActionType.Recalled; var costOwnerNotification = new EmailNotificationMessage <CostNotificationObject>(actionType, costOwner.GdamUserId); AddSharedTo(costOwnerNotification); MapEmailNotificationObject(costOwnerNotification.Object, cost, costOwner); await PopulateOtherFieldsForRecall(costOwnerNotification, Constants.EmailNotificationParents.CostOwner, timestamp, cost.Id, costStageRevision.Id); await PopulateMetadata(costOwnerNotification.Object, cost.Id); notifications.Add(costOwnerNotification); var approvals = await _approvalService.GetApprovalsByCostStageRevisionId(costStageRevision.Id); if (approvals == null) { //No approvals set return(notifications); } var technicalApprovals = approvals.Where(a => a.Type == ApprovalType.IPM).ToArray(); foreach (var technicalApproval in technicalApprovals) { foreach (var approvalMember in technicalApproval.ApprovalMembers) { //Send notifications to Technical Approver await AddApproverNotification(notifications, cost, costOwner, costStageRevision, timestamp, actionType, approvalMember.CostUser); } } var brandApprovals = approvals.Where(a => a.Type == ApprovalType.Brand).ToArray(); foreach (var brandApproval in brandApprovals) { foreach (var approvalMember in brandApproval.ApprovalMembers) { //Send notifications to actual Brand Approvers only if (approvalMember.IsSystemApprover()) { continue; } await AddApproverNotification(notifications, cost, costOwner, costStageRevision, timestamp, actionType, approvalMember.CostUser); } if (brandApproval.Requisitioners == null) { continue; } foreach (var requisitioner in brandApproval.Requisitioners) { await AddApproverNotification(notifications, cost, costOwner, costStageRevision, timestamp, actionType, requisitioner.CostUser); } } await AddFinanceManagerNotification(actionType, cost, costUsers, costStageRevision, timestamp, notifications); return(notifications); }
public async Task <bool> CostHasBeenSubmitted(Guid costId, Guid userId) { if (costId == Guid.Empty) { return(false); } if (userId == Guid.Empty) { return(false); } var cost = await _efContext.Cost .Include(c => c.LatestCostStageRevision) .ThenInclude(csr => csr.CostStage) .ThenInclude(cs => cs.CostStageRevisions) .Include(c => c.LatestCostStageRevision) .Include(c => c.CostStages) .ThenInclude(cs => cs.CostStageRevisions) .ThenInclude(csr => csr.Approvals) .ThenInclude(a => a.ApprovalMembers) .ThenInclude(am => am.CostUser) .Include(c => c.Project) .ThenInclude(p => p.Brand) .IncludeCostOwner() .FirstOrDefaultAsync(c => c.Id == costId); var latestRevision = cost.LatestCostStageRevision; var costOwner = cost.Owner; var insuranceUsers = await _costUserService.GetInsuranceUsers(costOwner.Agency); var financeManagementUsers = await _costUserService.GetFinanceManagementUsers(cost.UserGroups, Constants.BudgetRegion.NorthAmerica); var costUsers = new CostNotificationUsers { CostOwner = cost.Owner, InsuranceUsers = insuranceUsers, FinanceManagementUsers = financeManagementUsers }; var notificationMessages = await _emailNotificationBuilder.BuildCostSubmittedNotification(costUsers, cost, latestRevision, DateTime.UtcNow); var notifications = notificationMessages.ToList(); //Upon Submit the next stage might be PendingTechnicalApproval or PendingBrandApproval or Approved for FA. var nextStatus = cost.Status; switch (nextStatus) { case CostStageRevisionStatus.Approved: // The Cost is auto approved when the budget does not change between cost stages. await BuildAutoApprovedNotification(costUsers, cost, latestRevision, notifications); break; case CostStageRevisionStatus.PendingBrandApproval: var pendingBrandNotifications = await _emailNotificationBuilder.BuildPendingBrandApprovalNotification(costUsers, cost, latestRevision, DateTime.UtcNow); notifications.AddRange(pendingBrandNotifications); //Enqueue reminder for the brand approvers. await _reminderService.CreateNew(cost.Id, DateTime.UtcNow.AddDays(1)); break; case CostStageRevisionStatus.PendingTechnicalApproval: var pendingTechnicalNotifications = await _emailNotificationBuilder.BuildPendingTechnicalApprovalNotification(costUsers, cost, latestRevision, DateTime.UtcNow); notifications.AddRange(pendingTechnicalNotifications); break; //ADC-2698 comment this line of code to take off the feature from release 1.9.4 // //Enqueue reminder for the technical approvers. // await _reminderService.CreateNew(cost.Id, DateTime.UtcNow.AddDays(2)); // break; } //Notify previous approvers if they've been removed if (cost.HasPreviousRevision()) { var previousRevision = cost.GetPreviousRevision(); var previousRevisionId = previousRevision.Id; //Get the approvers for the previous revision previousRevision.Approvals = await _approvalService.GetApprovalsByCostStageRevisionId(previousRevisionId); var csrAnalyser = new CostStageRevisionAnalyser(); IEnumerable <ApprovalMember> removedApprovers = csrAnalyser.GetRemovedApprovers(previousRevision, latestRevision); var removedApproverNotifications = await _emailNotificationBuilder.BuildPreviousApproverNotification(costUsers, removedApprovers, cost, previousRevision, DateTime.UtcNow); notifications.AddRange(removedApproverNotifications); } bool sent = false; foreach (var message in notifications) { sent = await _paperPusherClient.SendMessage(message); } return(sent); }