private Guid AddNotificationBatch(GenericNotificationViewModel model) { //Add the Notification Batch ..... var notificationTemplate = _notificationTemplatesService.GetByKey(model.NotificationTemplateKey); if (notificationTemplate != null) { NotificationBatch notificationBatch = new NotificationBatch(); Guid batchGuid = Guid.NewGuid(); notificationBatch.StartDate = model.CurrentDate; if (!string.IsNullOrEmpty(model.NotificationTemplateKey)) { notificationBatch.ResourceType = model.NotificationTemplateKey.Split('.')[0]; notificationBatch.ResourceAction = model.NotificationTemplateKey.Split('.')[1]; } notificationBatch.AdditionalMessage = ""; notificationBatch.ResourceId = model.ResourceId; notificationBatch.NotificationBatchGuid = batchGuid; notificationBatch.NotificationTemplateGuid = notificationTemplate.NotificationTemplateGuid; notificationBatch.CreatedBy = model.CurrentUserGuid; notificationBatch.CreatedOn = model.CurrentDate; _notificationBatchService.Add(notificationBatch); return(batchGuid); } return(Guid.Empty); }
public void SendEmailToRespectivePersonnel(int status, Guid contractGuid) { var jobRequestEntity = _jobRequestService.GetDetailsForJobRequestById(contractGuid); var model = ContractsMapper.MapJobRequestToViewModel(jobRequestEntity); var keyPersonnel = _contractRefactorService.GetKeyPersonnelByContractGuid(contractGuid); var param = new { id = contractGuid }; var link = RouteUrlHelper.GetAbsoluteAction(_urlHelper, "JobRequest", "Detail", param); //var urlLink = new UrlHelper(ControllerContext.RequestContext); JobRequestEmailModel emailModel = new JobRequestEmailModel(); emailModel.ContractNumber = model.BasicContractInfo.ContractNumber; emailModel.ProjectNumber = model.BasicContractInfo.ProjectNumber; emailModel.AwardingAgency = model.CustomerInformation.AwardingAgencyOfficeName; emailModel.FundingAgency = model.CustomerInformation.FundingAgencyOfficeName; emailModel.ClickableUrl = link; emailModel.Status = "In Progress"; string emailTo = "*****@*****.**"; string recipientName = string.Empty; string subject = string.Empty; Guid notifyTo = UserHelper.CurrentUserGuid(HttpContext); var notificationTemplate = _notificationTemplatesService.GetByKey("jobrequest-notify"); var content = string.Empty; var template = string.Empty; if (notificationTemplate != null) { template = notificationTemplate.Message; } //for filtering the representative to send email switch (status) { case (int)JobRequestStatus.ContractRepresentative: var controlRepresentative = model.KeyPersonnel.ProjectControls; if (controlRepresentative != null) { notifyTo = controlRepresentative; } var projectUser = _userService.GetUserByUserGuid(notifyTo); if (projectUser != null) { //emailTo = contractUser.WorkEmail; recipientName = projectUser.DisplayName; emailModel.ReceipentName = recipientName; subject = "A new Job Request Form has been submitted for contract: " + emailModel.ContractNumber; } var conManager = _userService.GetUserByUserGuid(model.KeyPersonnel.ProjectManager); emailModel.NotifiedTo = conManager.Firstname + " " + conManager.Lastname; var submittedBy = _userService.GetUserByUserGuid(model.KeyPersonnel.ContractRepresentative); emailModel.SubmittedBy = submittedBy.Firstname + " " + submittedBy.Lastname; break; case (int)JobRequestStatus.ProjectControl: var projectRepresentative = model.KeyPersonnel.ProjectManager; if (projectRepresentative != null) { notifyTo = projectRepresentative; } var managerUser = _userService.GetUserByUserGuid(notifyTo); if (managerUser != null) { //emailTo = controlUser.WorkEmail; recipientName = managerUser.DisplayName; emailModel.ReceipentName = recipientName; subject = "A new Job Request Form has been submitted for contract: " + emailModel.ContractNumber; } var manager = _userService.GetUserByUserGuid(model.KeyPersonnel.ProjectManager); emailModel.NotifiedTo = manager.Firstname + " " + manager.Lastname; var submittedByProject = _userService.GetUserByUserGuid(model.KeyPersonnel.ProjectControls); emailModel.SubmittedBy = submittedByProject.Firstname + " " + submittedByProject.Lastname; break; case (int)JobRequestStatus.ProjectManager: var managerRepresentative = model.KeyPersonnel.AccountingRepresentative; if (managerRepresentative != null) { notifyTo = managerRepresentative; } var accountManager = _userService.GetUserByUserGuid(notifyTo); if (accountManager != null) { //emailTo = projectManager.WorkEmail; recipientName = accountManager.DisplayName; emailModel.ReceipentName = recipientName; subject = "A new Job Request Form has been submitted for contract: " + emailModel.ContractNumber; } var submittedByManager = _userService.GetUserByUserGuid(model.KeyPersonnel.ProjectManager); emailModel.SubmittedBy = submittedByManager.Firstname + " " + submittedByManager.Lastname; break; case (int)JobRequestStatus.Accounting: var accountUser = _userService.GetUserByUserGuid(notifyTo); if (accountUser != null) { //emailTo = accountUser.WorkEmail; recipientName = accountUser.DisplayName; emailModel.ReceipentName = recipientName; subject = "Job Request has been set to done contract: " + emailModel.ContractNumber; } var submittedByAccount = _userService.GetUserByUserGuid(model.KeyPersonnel.AccountingRepresentative); emailModel.SubmittedBy = submittedByAccount.Firstname + " " + submittedByAccount.Lastname; emailModel.Status = "Done"; break; default: break; } content = EmailHelper.GetContentForJobRequestNotify(template, keyPersonnel, emailModel); _emailSender.SendEmailAsync(emailTo, recipientName, subject, content); }