Example #1
0
        public IActionResult Edit(Guid id)
        {
            try
            {
                var jobRequestEntity = _jobRequestService.GetDetailsForJobRequestById(id);
                var model            = ContractsMapper.MapJobRequestToViewModel(jobRequestEntity);

                if (model.Parent_ContractGuid == null)
                {
                    model.BaseUrl = "Contract";
                }
                else
                {
                    model.BaseUrl = "Project";
                    var parentContractDetails = _contractRefactorService.GetBasicContractById(model.Parent_ContractGuid ?? Guid.Empty);
                    var parentContractNumber  = parentContractDetails == null ? "N/A" : parentContractDetails.ContractNumber;
                    model.BasicContractInfo.ParentProjectNumber = parentContractDetails == null ? "N/A" : parentContractDetails.ProjectNumber;
                }
                var companyListEntity = _jobRequestService.GetCompanyData();
                var companyList       = _mapper.Map <ICollection <Models.ViewModels.KeyValuePairModel <Guid, string> > >(companyListEntity);
                var companies         = model.Companies;

                var questionaire = _mapper.Map <Models.ViewModels.Contract.ContractQuestionaireViewModel>(jobRequestEntity.Contracts.ContractQuestionaire);
                model.ContractQuestionaire = questionaire;
                List <string> companySelected = new List <string>();
                if (!string.IsNullOrEmpty(companies))
                {
                    var listCompany = companies.Split(",");
                    foreach (var name in listCompany)
                    {
                        companySelected.Add(name);
                    }
                }

                model.CompanySelected = companySelected;
                model.companyList     = companyList;
                model.radioIsIntercompanyWorkOrder = KeyValueHelper.GetYesNo();
                model.ContractGuid         = id;
                model.JobRequestGuid       = id;
                model.farContractViewModel = GetFarContract(model.ContractGuid);
                return(View(model));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
                return(BadRequest(ModelState));
            }
        }
Example #2
0
        public IActionResult Add(Guid id)
        {
            try
            {
                var jobRequestEntity  = _jobRequestService.GetDetailsForJobRequestById(id);
                var model             = ContractsMapper.MapJobRequestToViewModel(jobRequestEntity);
                var companyListEntity = _jobRequestService.GetCompanyData();
                var companyList       = _mapper.Map <ICollection <Models.ViewModels.KeyValuePairModel <Guid, string> > >(companyListEntity);
                if (model.Parent_ContractGuid == null)
                {
                    model.BaseUrl = "Contract";
                }
                else
                {
                    model.BaseUrl = "Project";
                    var parentContractDetails = _contractRefactorService.GetBasicContractById(model.Parent_ContractGuid ?? Guid.Empty);
                    var parentContractNumber  = parentContractDetails == null ? "N/A" : parentContractDetails.ContractNumber;
                    model.BasicContractInfo.ParentProjectNumber = parentContractDetails == null ? "N/A" : parentContractDetails.ProjectNumber;
                }
                model.companyList = companyList;
                model.Status      = (int)JobRequestStatus.ContractRepresentative;
                model.radioIsIntercompanyWorkOrder = KeyValueHelper.GetYesNo();
                model.ContractGuid = id;

                var questionaire = _mapper.Map <Models.ViewModels.Contract.ContractQuestionaireViewModel>(jobRequestEntity.Contracts.ContractQuestionaire);
                model.ContractQuestionaire = questionaire;
                model.farContractViewModel = GetFarContract(model.ContractGuid);
                model.IsNew = true;
                return(View(model));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(e.ToString(), e.Message);
                return(BadRequest(ModelState));
            }
        }
Example #3
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);
            }
        }
Example #4
0
        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);
        }