public NotificationTemplate GetNotificationTemplateAsResource(NotificationTemplatesDetail notificationTemplatesDetail, string resourcekey)
        {
            var    notificationTemplate = GetByKey(resourcekey);
            string revenueRecognition   = (EnumGlobal.ResourceType.RevenueRecognition.ToString()).ToUpper();
            string contractClose        = (EnumGlobal.ResourceType.ContractCloseOut.ToString()).ToUpper();
            var    key = resourcekey.Split('.')[0].ToUpper();

            if (key == revenueRecognition)
            {
                string message = revenueEmailtemplates(notificationTemplatesDetail, notificationTemplate);

                notificationTemplate.Message = message;
                StringBuilder content = new StringBuilder(notificationTemplate.Subject);
                notificationTemplate.Subject = content.Replace("{PROJECT_NUMBER}", notificationTemplatesDetail.ProjectNumber).ToString();
                return(notificationTemplate);
            }
            else if (key == contractClose)
            {
                string message = contractCloseEmailtemplates(notificationTemplatesDetail, notificationTemplate);

                notificationTemplate.Message = message;
                StringBuilder content = new StringBuilder(notificationTemplate.Subject);
                content.Replace("{PROJECT_NUMBER}", notificationTemplatesDetail.ProjectNumber).ToString();
                content.Replace("{CONTRACT_NUMBER}", notificationTemplatesDetail.ContractNumber).ToString();
                content.Replace("{CONTRACT_CONTRACT_TYPE}", notificationTemplatesDetail.ContractType).ToString();
                content.Replace("{SUBMITTED_NAME}", notificationTemplatesDetail.SubmittedByName);
                content.Replace("{CONTRACT_DESCRIPTION}", notificationTemplatesDetail.Description);
                content.Replace("{CONTRACT_TITLE}", notificationTemplatesDetail.ContractTitle);
                notificationTemplate.Subject = content.ToString();
                return(notificationTemplate);
            }
            return(null);
        }
示例#2
0
        public static string GetContentForNotify(string template, NotificationTemplatesDetail model)
        {
            StringBuilder content = new StringBuilder(template);

            var receiverDisplayName = (string.IsNullOrEmpty(model.ReceiverDisplayName) ? string.Empty : model.ReceiverDisplayName);

            content.Replace("{RECEIVER_NAME}", (string.IsNullOrEmpty(model.ReceiverDisplayName) ? string.Empty : model.ReceiverDisplayName));
            content.Replace("{SUBMITTED_NAME}", (string.IsNullOrEmpty(model.SubmittedByName) ? string.Empty : model.SubmittedByName));
            content.Replace("{CONTRACT_NUMBER}", (string.IsNullOrEmpty(model.ContractNumber) ? string.Empty : model.ContractNumber));
            content.Replace("{AWARDING_AGENCY}", (string.IsNullOrEmpty(model.AwardingAgency) ? string.Empty : model.AwardingAgency));
            content.Replace("{FUNDING_AGENCY}", (string.IsNullOrEmpty(model.FundingAgency) ? string.Empty : model.FundingAgency));
            content.Replace("{TASK_ORDERNUMBER}", (string.IsNullOrEmpty(model.TaskOrderNumber) ? string.Empty : model.TaskOrderNumber));
            content.Replace("{PROJECT_NUMBER}", (string.IsNullOrEmpty(model.ProjectNumber) ? string.Empty : model.ProjectNumber));
            content.Replace("{CONTRACT_TITLE}", (string.IsNullOrEmpty(model.ContractTitle) ? string.Empty : model.ContractTitle));
            content.Replace("{TASKORDER_TITLE}", (string.IsNullOrEmpty(model.ContractTitle) ? string.Empty : model.ContractTitle));
            content.Replace("{TITLE}", (string.IsNullOrEmpty(model.ContractTitle) ? string.Empty : model.ContractTitle));
            content.Replace("{SUBMITTED_BY}", (string.IsNullOrEmpty(model.SubmittedByName) ? string.Empty : model.SubmittedByName));
            content.Replace("{STATUS}", (string.IsNullOrEmpty(model.Status) ? string.Empty : model.Status));
            content.Replace("{KEY_PERSONNELLIST}", (string.IsNullOrEmpty(model.AdditionalUser) ? string.Empty : model.AdditionalUser));
            content.Replace("{JOBREQUEST_URL}", (string.IsNullOrEmpty(model.RedirectUrlPath) ? string.Empty : model.RedirectUrlPath));
            content.Replace("{NOTIFY_TO}", (string.IsNullOrEmpty(model.ReceiverDisplayName) ? string.Empty : model.ReceiverDisplayName));
            content.Replace("{NOTIFY_OTHER}", (string.IsNullOrEmpty(model.AdditionalUser) ? string.Empty : model.AdditionalUser));
            content.Replace("{ADDITIONAL_RECIPIENT}", (string.IsNullOrEmpty(model.AdditionalUser) ? string.Empty : model.AdditionalUser));
            content.Replace("{ADDITIONAL_MESSAGE}", (string.IsNullOrEmpty(model.AdditionalMessage) ? string.Empty : model.AdditionalMessage));
            content.Replace("{REQUESTEDBY_NAME}", (string.IsNullOrEmpty(model.ReceiverDisplayName) ? string.Empty : model.ReceiverDisplayName));
            content.Replace("{CONTRACT_TYPE}", (string.IsNullOrEmpty(model.ContractType) ? string.Empty : model.ContractType));
            content.Replace("{Contract_type}", (string.IsNullOrEmpty(model.ContractType) ? string.Empty : model.ContractType));
            content.Replace("{PROJECT_NUMBER}", (string.IsNullOrEmpty(model.ProjectNumber) ? string.Empty : model.ProjectNumber));
            content.Replace("{ThresholdAward_Amount}", (string.IsNullOrEmpty(model.ThresholdAmount.ToString()) ? string.Empty : model.ThresholdAmount.ToString()));
            content.Replace("{MOD_NUMBER}", (string.IsNullOrEmpty(model.ModNumber) ? string.Empty : model.ModNumber));
            content.Replace("{Redirect_Url}", (string.IsNullOrEmpty(model.RedirectUrlPath) ? string.Empty : model.RedirectUrlPath));
            content.Replace("{REDIRECT_URL}", (string.IsNullOrEmpty(model.RedirectUrlPath) ? string.Empty : model.RedirectUrlPath));
            content.Replace("{CONTRACT_DESCRIPTION}", (string.IsNullOrEmpty(model.Description) ? string.Empty : model.Description));
            return(content.ToString());
        }
        private string contractCloseEmailtemplates(NotificationTemplatesDetail detail, NotificationTemplate notificationTemplate)
        {
            var           additionalMsg = string.IsNullOrEmpty(detail.AdditionalMessage) ? "No additional message was added" : detail.AdditionalMessage;
            StringBuilder content       = new StringBuilder(notificationTemplate.Message);

            content.Replace("{REQUESTEDBY_NAME}", detail.ReceiverDisplayName);
            content.Replace("{CONTRACT_NUMBER}", detail.ContractNumber);
            content.Replace("{PROJECT_NUMBER}", detail.ProjectNumber);
            content.Replace("{TITLE}", detail.Title);
            content.Replace("{CONTRACT_TYPE}", detail.ContractType);
            content.Replace("{CONTRACT_TITLE}", detail.ContractTitle);
            content.Replace("{Redirect_Url}", detail.RedirectUrlPath);
            content.Replace("{REDIRECT_URL}", detail.RedirectUrlPath);
            content.Replace("{SUBMITTED_NAME}", detail.SubmittedByName);
            content.Replace("{ADDITIONAL_MESSAGE}", additionalMsg);
            content.Replace("{NOTIFY_OTHER}", detail.NotifyOther);
            content.Replace("{CONTRACT_DESCRIPTION}", detail.Description);
            return(content.ToString());
        }
        private string revenueEmailtemplates(NotificationTemplatesDetail detail, NotificationTemplate notificationTemplate)
        {
            var           additionalMsg = string.IsNullOrEmpty(detail.AdditionalMessage) ? "No additional message was added" : detail.AdditionalMessage;
            StringBuilder content       = new StringBuilder(notificationTemplate.Message);

            content.Replace("{REQUESTEDBY_NAME}", detail.ReceiverDisplayName);
            content.Replace("{CONTRACT_NUMBER}", detail.ContractNumber);
            content.Replace("{PROJECT_NUMBER}", detail.ProjectNumber);
            content.Replace("{TITLE}", detail.Title);
            content.Replace("{CONTRACT_NUMBER}", detail.ContractNumber);
            content.Replace("{CONTRACT_TYPE}", detail.ContractType);
            content.Replace("{TASKORDER_NUMBER}", detail.TaskOrderNumber);
            content.Replace("{TASKORDER_TITLE}", detail.ContractTitle);
            content.Replace("{ThresholdAward_Amount}", detail.ThresholdAmount.ToString());
            content.Replace("{THRESHOLD_AMOUNT}", detail.ThresholdAmount.ToString());
            content.Replace("{MOD_NUMBER}", detail.ModNumber);
            content.Replace("{NOTIFY_OTHER}", detail.NotifyOther);
            content.Replace("{ADDITIONAL_MESSAGE}", additionalMsg);
            content.Replace("{CONTRACT_TITLE}", detail.ContractTitle);
            content.Replace("{Redirect_Url}", detail.RedirectUrlPath);
            content.Replace("{REDIRECT_URL}", detail.RedirectUrlPath);
            content.Replace("{CONTRACT_DESCRIPTION}", detail.Description);
            return(content.ToString());
        }
        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);
            }
        }
示例#6
0
        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);
            }
        }
 public NotificationTemplate GetNotificationTemplateAsResource(NotificationTemplatesDetail notificationTemplatesDetail, string resourcekey)
 {
     return(_emailTemplatesRepository.GetNotificationTemplateAsResource(notificationTemplatesDetail, resourcekey));
 }