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 bool AddNotificationMessage(GenericNotificationViewModel model) { foreach (var item in model.IndividualRecipients) { var senderDetails = _userService.GetUserByUserGuid(model.CurrentUserGuid); var link = model.RedirectUrl; Guid notificationBatchGuid = AddNotificationBatch(model); if (notificationBatchGuid != Guid.Empty) { // Notification Templates var notificationTemplate = _notificationTemplatesService.GetNotificationTemplateByKey(model.NotificationTemplateKey); model.NotificationTemplatesDetail.ReceiverDisplayName = item.DisplayName; model.NotificationTemplatesDetail.SubmittedByName = senderDetails.DisplayName; model.NotificationTemplatesDetail.RedirectUrlPath = model.RedirectUrl; var message = GetContentForNotify(notificationTemplate.Message, model.NotificationTemplatesDetail); var subject = GetContentForNotify(notificationTemplate.Subject, model.NotificationTemplatesDetail); var notificationMessage = new NotificationMessage { NotificationBatchGuid = notificationBatchGuid, UserGuid = item.UserGuid, Subject = subject, Message = message, AdditionalMessage = "", Status = false, UserResponse = false, NextAction = model.CurrentDate, CreatedOn = model.CurrentDate, CreatedBy = model.CurrentUserGuid, }; if (model.SendEmail) { _emailSender.SendEmailAsync(item.WorkEmail, item.DisplayName, subject, message); } return(_notificationMessageService.Add(notificationMessage)); } } return(false); }
private bool AddNotificationMessage(ContractNotificationModel contractModel) { try { var notificationModel = new GenericNotificationViewModel(); var notificationTemplatesDetails = new NotificationTemplatesDetail(); var userList = new List <User>(); var receiverInfo = new User(); Guid? receiverGuid = Guid.Empty; decimal thresholdAmount = 0.00M; notificationModel.ResourceId = contractModel.ContractGuid; notificationModel.RedirectUrl = _configuration.GetSection("SiteUrl").Value + ("/contract/Details/" + contractModel.ContractGuid); notificationModel.NotificationTemplateKey = contractModel.key; notificationModel.CurrentDate = CurrentDateTimeHelper.GetCurrentDateTime(); notificationModel.CurrentUserGuid = UserHelper.CurrentUserGuid(HttpContext); notificationModel.SendEmail = true; var keyPersonnels = _contractService.GetKeyPersonnelByContractGuid(contractModel.ContractGuid); if (keyPersonnels?.Any() == true) { receiverGuid = keyPersonnels.FirstOrDefault(x => x.UserRole == ContractUserRole._contractRepresentative)?.UserGuid; if (receiverGuid != Guid.Empty) { thresholdAmount = RevenueRecognitionHelper.GetAmountByContractType(_configuration, contractModel.ContractType); receiverInfo = _userService.GetUserByUserGuid(receiverGuid ?? Guid.Empty); var resourcevalue = _resourceAttributeValueService.GetResourceAttributeValueByValue(contractModel.ContractType); string contracttype = string.Empty; if (resourcevalue != null) { contracttype = resourcevalue.Name; } if (receiverInfo != null) { userList.Add(receiverInfo); notificationModel.IndividualRecipients = userList; } var keyList = "<ul>"; keyList += "<li>" + receiverInfo.DisplayName + " (" + receiverInfo.JobTitle + ")" + "</li>"; StringBuilder additionalUser = new StringBuilder(keyList); notificationTemplatesDetails.ContractNumber = contractModel.ContractNumber; notificationTemplatesDetails.Title = contractModel.ContractTitle; notificationTemplatesDetails.ContractType = contracttype; notificationTemplatesDetails.ContractTitle = contractModel.ContractTitle; notificationTemplatesDetails.ProjectNumber = contractModel.ProjectNumber; notificationTemplatesDetails.AdditionalUser = additionalUser.ToString(); notificationTemplatesDetails.ThresholdAmount = thresholdAmount; notificationTemplatesDetails.Status = ""; notificationModel.NotificationTemplatesDetail = notificationTemplatesDetails; _genericNotificationService.AddNotificationMessage(notificationModel); return(true); } } return(false); } catch (Exception ex) { var userGuid = UserHelper.CurrentUserGuid(HttpContext); EventLogHelper.Error(_eventLogger, new EventLog { EventGuid = Guid.NewGuid(), Action = "Index", Application = "ESS", EventDate = DateTime.UtcNow, Message = ex.Message, Resource = ResourceType.Contract.ToString(), StackTrace = ex.StackTrace, UserGuid = userGuid }); return(false); } }
private bool SendNotification(Guid resourceId, Guid contractGuid, int currentStage) { try { var notificationModel = new GenericNotificationViewModel(); var notificationTemplatesDetails = new NotificationTemplatesDetail(); var userList = new List <User>(); var receiverInfo = new User(); var receiverGuid = Guid.Empty; notificationModel.ResourceId = resourceId; notificationModel.RedirectUrl = _configuration.GetSection("SiteUrl").Value + ("/JobRequest/Detail/" + contractGuid); notificationModel.NotificationTemplateKey = Infrastructure.Helpers.FormatHelper.ConcatResourceTypeAndAction (EnumGlobal.ResourceType.JobRequest.ToString(), EnumGlobal.CrudType.Notify.ToString()); notificationModel.CurrentDate = CurrentDateTimeHelper.GetCurrentDateTime(); notificationModel.CurrentUserGuid = UserHelper.CurrentUserGuid(HttpContext); notificationModel.SendEmail = true; var jobRequestEntity = _jobRequestService.GetDetailsForJobRequestById(contractGuid); var model = ContractsMapper.MapJobRequestToViewModel(jobRequestEntity); var keyPersonnels = _contractRefactorService.GetKeyPersonnelByContractGuid(contractGuid); if (keyPersonnels?.Any() == true) { switch (currentStage) { case (int)JobRequestStatus.ProjectControl: var projectControls = keyPersonnels.FirstOrDefault(x => x.UserRole == ContractUserRole._projectControls); if (projectControls != null) { receiverGuid = projectControls.UserGuid; } break; case (int)JobRequestStatus.ProjectManager: var projectManager = keyPersonnels.FirstOrDefault(x => x.UserRole == ContractUserRole._projectManager); if (projectManager != null) { receiverGuid = projectManager.UserGuid; } break; case (int)JobRequestStatus.Accounting: var accountRepresentative = keyPersonnels.FirstOrDefault(x => x.UserRole == ContractUserRole._accountRepresentative); if (accountRepresentative != null) { receiverGuid = accountRepresentative.UserGuid; } break; } receiverInfo = _userService.GetUserByUserGuid(receiverGuid); if (receiverInfo != null) { userList.Add(receiverInfo); notificationModel.IndividualRecipients = userList; } var keyList = "<ul>"; foreach (var person in keyPersonnels) { keyList += "<li>" + person.User.DisplayName + " (" + person.UserRole + ")" + "</li>"; } keyList += "</li>"; StringBuilder additionalUser = new StringBuilder(keyList); notificationTemplatesDetails.ContractNumber = model.BasicContractInfo.ContractNumber; notificationTemplatesDetails.AwardingAgency = model.CustomerInformation.AwardingAgencyOfficeName; notificationTemplatesDetails.FundingAgency = model.CustomerInformation.FundingAgencyOfficeName; notificationTemplatesDetails.ProjectNumber = model.BasicContractInfo.ProjectNumber; notificationTemplatesDetails.ContractTitle = model.BasicContractInfo.ContractTitle; notificationTemplatesDetails.Description = model.BasicContractInfo.Description; notificationTemplatesDetails.AdditionalUser = additionalUser.ToString(); notificationTemplatesDetails.Status = ""; notificationModel.NotificationTemplatesDetail = notificationTemplatesDetails; _genericNotificationService.AddNotificationMessage(notificationModel); return(true); } return(false); } catch (Exception ex) { var userGuid = UserHelper.CurrentUserGuid(HttpContext); EventLogHelper.Error(_eventLogger, new EventLog { EventGuid = Guid.NewGuid(), Action = "Index", Application = "ESS", EventDate = DateTime.UtcNow, Message = ex.Message, Resource = ResourceType.Contract.ToString(), StackTrace = ex.StackTrace, UserGuid = userGuid }); return(false); } }