protected async Task <IActionResult> SubmitGatewayPageAnswer(SubmitGatewayPageAnswerCommand command) { var username = HttpContext.User.UserDisplayName(); var userId = HttpContext.User.UserId(); var comments = GetCommentsFromCommand(command); var clarificationAnswer = command.ClarificationAnswer; _logger.LogInformation($"{typeof(T).Name}-SubmitGatewayPageAnswer - ApplicationId '{command.ApplicationId}' - PageId '{command.PageId}' - Status '{command.Status}' - UserName '{username}' - Comments '{comments}' - ClarificationAnswer {clarificationAnswer}"); try { await _applyApiClient.SubmitGatewayPageAnswer(command.ApplicationId, command.PageId, command.Status, userId, username, comments, clarificationAnswer); } catch (Exception ex) { _logger.LogError(ex, $"{typeof(T).Name}-SubmitGatewayPageAnswer - Error: '{ex.Message}'"); throw; } return(RedirectToAction("ViewApplication", "RoatpGateway", new { command.ApplicationId }, $"Sequence_{command.SequenceNumber}")); }
public async Task <IActionResult> ClarifySubcontractorDeclarationPage(SubmitGatewayPageAnswerCommand command) { var userId = HttpContext.User.UserId(); var username = HttpContext.User.UserDisplayName(); var isClarificationFileUpdate = HttpContext.Request.Form["submitClarificationFile"].Count != 0; var isClarificationForm = HttpContext.Request.Form["submitClarificationForm"].Count != 0; var isRemoveClarificationFile = HttpContext.Request.Form["removeClarificationFile"].Count != 0; var filesToUpload = HttpContext.Request.Form.Files; if (isClarificationFileUpdate) { var validationResponse = GatewayValidator.ValidateClarificationFileUpload(filesToUpload); if (validationResponse.Errors != null && validationResponse.Errors.Count > 0) { var viewModel = await _orchestrator.GetSubcontractorDeclarationViewModel( new GetSubcontractorDeclarationRequest(command.ApplicationId, userId, username)); HydrateSucontractorDeclarationViewModelFromCommand(command, viewModel); viewModel.ErrorMessages = validationResponse.Errors; return(View($"{GatewayViewsLocation}/Clarifications/SubcontractorDeclaration.cshtml", viewModel)); } var newClarificationVm = await ProcessSubcontractorDeclarationuploadAndRebuildViewModel(command, filesToUpload); return(View($"{GatewayViewsLocation}/Clarifications/SubcontractorDeclaration.cshtml", newClarificationVm)); } if (isRemoveClarificationFile) { var newClarificationVm = await RemoveSubcontractorDeclarationuploadAndRebuildViewModel(command); return(View($"{GatewayViewsLocation}/Clarifications/SubcontractorDeclaration.cshtml", newClarificationVm)); } Func <Task <SubcontractorDeclarationViewModel> > viewModelBuilder = () => _orchestrator.GetSubcontractorDeclarationViewModel(new GetSubcontractorDeclarationRequest(command.ApplicationId, userId, username)); return(await ValidateAndUpdateClarificationPageAnswer(command, viewModelBuilder, $"{GatewayViewsLocation}/Clarifications/SubcontractorDeclaration.cshtml")); }
public void post_organisation_status_path_with_errors() { var applicationId = Guid.NewGuid(); var pageId = "1-20"; var viewModel = new OrganisationStatusViewModel() { Status = SectionReviewStatus.Fail, SourcesCheckedOn = DateTime.Now, ErrorMessages = new List <ValidationErrorDetail>() }; viewModel.ApplicationId = applicationId; viewModel.PageId = viewModel.PageId; viewModel.SourcesCheckedOn = DateTime.Now; var command = new SubmitGatewayPageAnswerCommand(viewModel); GatewayValidator.Setup(v => v.Validate(command)) .ReturnsAsync(new ValidationResponse { Errors = new List <ValidationErrorDetail> { new ValidationErrorDetail { Field = "OptionFail", ErrorMessage = "needs text" } } } ); _orchestrator.Setup(x => x.GetOrganisationStatusViewModel(It.IsAny <GetOrganisationStatusRequest>())) .ReturnsAsync(viewModel) .Verifiable("view model not returned"); ApplyApiClient.Setup(x => x.SubmitGatewayPageAnswer(applicationId, pageId, viewModel.Status, UserId, Username, It.IsAny <string>())); var result = _controller.EvaluateOrganisationStatus(command).Result; ApplyApiClient.Verify(x => x.SubmitGatewayPageAnswer(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never); _orchestrator.Verify(x => x.GetTradingNameViewModel(It.IsAny <GetTradingNameRequest>()), Times.Never()); }
public void post_legal_name_path_with_errors() { var applicationId = Guid.NewGuid(); var pageId = "1-20"; var vm = new LegalNamePageViewModel { Status = SectionReviewStatus.Fail, SourcesCheckedOn = DateTime.Now, ErrorMessages = new List <ValidationErrorDetail>() }; vm.ApplicationId = applicationId; vm.PageId = vm.PageId; vm.SourcesCheckedOn = DateTime.Now; var command = new SubmitGatewayPageAnswerCommand(vm); GatewayValidator.Setup(v => v.Validate(command)) .ReturnsAsync(new ValidationResponse { Errors = new List <ValidationErrorDetail> { new ValidationErrorDetail { Field = "OptionFail", ErrorMessage = "needs text" } } } ); _orchestrator.Setup(x => x.GetLegalNameViewModel(It.Is <GetLegalNameRequest>(y => y.ApplicationId == vm.ApplicationId && y.UserName == Username))).ReturnsAsync(vm); var pageData = JsonConvert.SerializeObject(vm); ApplyApiClient.Setup(x => x.SubmitGatewayPageAnswer(applicationId, pageId, vm.Status, UserId, Username, It.IsAny <string>())); var result = _controller.EvaluateLegalNamePage(command).Result; ApplyApiClient.Verify(x => x.SubmitGatewayPageAnswer(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public void post_website_address_happy_path() { var applicationId = Guid.NewGuid(); var pageId = GatewayPageIds.WebsiteAddress; var vm = new WebsiteViewModel { ApplicationId = applicationId, Status = SectionReviewStatus.Pass, SourcesCheckedOn = DateTime.Now, ErrorMessages = new List <ValidationErrorDetail>(), OptionPassText = comment, PageId = pageId }; var command = new SubmitGatewayPageAnswerCommand(vm); var result = _controller.EvaluateWebsitePage(command).Result; ApplyApiClient.Verify(x => x.SubmitGatewayPageAnswer(applicationId, pageId, vm.Status, UserId, Username, comment, null)); _orchestrator.Verify(x => x.GetWebsiteViewModel(new GetWebsiteRequest(applicationId, UserId, Username)), Times.Never()); }
public void post_organisation_risk_clarification_path_with_errors() { var applicationId = Guid.NewGuid(); var pageId = GatewayPageIds.OrganisationRisk; var vm = new OrganisationRiskViewModel { ApplicationId = applicationId, PageId = pageId, Status = SectionReviewStatus.Fail, SourcesCheckedOn = DateTime.Now, ErrorMessages = new List <ValidationErrorDetail>(), ClarificationAnswer = ClarificationAnswer }; var command = new SubmitGatewayPageAnswerCommand(vm); _gatewayValidator.Setup(v => v.ValidateClarification(command)) .ReturnsAsync(new ValidationResponse { Errors = new List <ValidationErrorDetail> { new ValidationErrorDetail { Field = "OptionFail", ErrorMessage = "needs text" } } } ); _orchestrator.Setup(x => x.GetOrganisationRiskViewModel(It.Is <GetOrganisationRiskRequest>(y => y.ApplicationId == vm.ApplicationId && y.UserName == username))).ReturnsAsync(vm); _applyApiClient.Setup(x => x.SubmitGatewayPageAnswer(applicationId, pageId, vm.Status, userId, username, comment)); var result = _controller.ClarifyOrganisationRiskPage(command).Result; _applyApiClient.Verify(x => x.SubmitGatewayPageAnswer(applicationId, pageId, vm.Status, userId, username, comment), Times.Never); }
public void post_organisation_status_happy_path() { var applicationId = Guid.NewGuid(); var pageId = "1-30"; var viewModel = new OrganisationStatusViewModel() { Status = SectionReviewStatus.Pass, SourcesCheckedOn = DateTime.Now, ErrorMessages = new List <ValidationErrorDetail>() }; viewModel.SourcesCheckedOn = DateTime.Now; var command = new SubmitGatewayPageAnswerCommand(viewModel); ApplyApiClient.Setup(x => x.SubmitGatewayPageAnswer(applicationId, pageId, viewModel.Status, UserId, Username, It.IsAny <string>())); var result = _controller.EvaluateOrganisationStatus(command).Result; ApplyApiClient.Verify(x => x.SubmitGatewayPageAnswer(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null), Times.Once); _orchestrator.Verify(x => x.GetOrganisationStatusViewModel(It.IsAny <GetOrganisationStatusRequest>()), Times.Never()); }
public async Task clarifying_roepao_without_required_fields_does_not_save() { var applicationId = Guid.NewGuid(); var pageId = GatewayPageIds.Roepao; var vm = new RoepaoPageViewModel { ApplicationId = applicationId, PageId = pageId, Status = SectionReviewStatus.Fail, SourcesCheckedOn = DateTime.Now, ErrorMessages = new List <ValidationErrorDetail>(), OptionFailText = null, ClarificationAnswer = ClarificationAnswer }; var command = new SubmitGatewayPageAnswerCommand(vm); _gatewayValidator.Setup(v => v.ValidateClarification(command)) .ReturnsAsync(new ValidationResponse { Errors = new List <ValidationErrorDetail> { new ValidationErrorDetail { Field = "OptionFail", ErrorMessage = "needs text" } } }); _orchestrator.Setup(x => x.GetRoepaoViewModel(It.Is <GetRoepaoRequest>(y => y.ApplicationId == vm.ApplicationId && y.UserName == username))).ReturnsAsync(vm); var result = await _controller.ClarifyRoepaoPage(command); _applyApiClient.Verify(x => x.SubmitGatewayPageAnswer(applicationId, pageId, vm.Status, userId, username, vm.OptionPassText, ClarificationAnswer), Times.Never); }
public async Task clarifying_office_for_students_without_required_fields_does_not_save() { var applicationId = Guid.NewGuid(); var pageId = GatewayPageIds.OfficeForStudents; var vm = new OfficeForStudentsViewModel { Status = SectionReviewStatus.Fail, SourcesCheckedOn = DateTime.Now, ErrorMessages = new List <ValidationErrorDetail>(), ApplicationId = applicationId, PageId = pageId, ClarificationAnswer = ClarificationAnswer }; var command = new SubmitGatewayPageAnswerCommand(vm); GatewayValidator.Setup(v => v.ValidateClarification(command)) .ReturnsAsync(new ValidationResponse { Errors = new List <ValidationErrorDetail> { new ValidationErrorDetail { Field = "OptionFail", ErrorMessage = "needs text" } } } ); _orchestrator.Setup(x => x.GetOfficeForStudentsViewModel(It.Is <GetOfficeForStudentsRequest>(y => y.ApplicationId == vm.ApplicationId && y.UserName == Username))).ReturnsAsync(vm); await _controller.ClarifyOfficeForStudentsPage(command); ApplyApiClient.Verify(x => x.SubmitGatewayPageAnswer(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), ClarificationAnswer), Times.Never); }
public async Task post_organisation_risk_happy_path() { var applicationId = Guid.NewGuid(); var pageId = GatewayPageIds.OrganisationRisk; var vm = new OrganisationRiskViewModel { ApplicationId = applicationId, PageId = pageId, Status = SectionReviewStatus.Pass, SourcesCheckedOn = DateTime.Now, ErrorMessages = new List <ValidationErrorDetail>(), OptionPassText = "Some pass text" }; var command = new SubmitGatewayPageAnswerCommand(vm); _gatewayValidator.Setup(v => v.Validate(command)).ReturnsAsync(new ValidationResponse { Errors = new List <ValidationErrorDetail>() }); await _controller.EvaluateOrganisationRiskPage(command); _applyApiClient.Verify(x => x.SubmitGatewayPageAnswer(applicationId, pageId, vm.Status, userId, username, vm.OptionPassText, null)); }
public async Task IcoNumber_without_required_fields_clarification_does_not_save() { var applicationId = Guid.NewGuid(); var pageId = GatewayPageIds.IcoNumber; var vm = new IcoNumberViewModel() { Status = SectionReviewStatus.Fail, SourcesCheckedOn = DateTime.Now, ErrorMessages = new List <ValidationErrorDetail>(), ApplicationId = applicationId, PageId = pageId, ClarificationAnswer = ClarificationAnswer }; var command = new SubmitGatewayPageAnswerCommand(vm); GatewayValidator.Setup(v => v.ValidateClarification(command)) .ReturnsAsync(new ValidationResponse { Errors = new List <ValidationErrorDetail> { new ValidationErrorDetail { Field = "OptionFail", ErrorMessage = "needs text" } } } ); _orchestrator.Setup(x => x.GetIcoNumberViewModel(It.Is <GetIcoNumberRequest>(y => y.ApplicationId == vm.ApplicationId && y.UserName == Username))).ReturnsAsync(vm); await _controller.ClarifyIcoNumberPage(command); ApplyApiClient.Verify(x => x.SubmitGatewayPageAnswer(applicationId, pageId, vm.Status, UserId, Username, ClarificationAnswer), Times.Never); }
private async Task <SubcontractorDeclarationViewModel> RemoveSubcontractorDeclarationuploadAndRebuildViewModel(SubmitGatewayPageAnswerCommand command) { var userId = HttpContext.User.UserId(); var username = HttpContext.User.UserDisplayName(); var fileRemovedSuccessfully = await _applyApiClient.RemoveSubcontractorDeclarationClarificationFile(command.ApplicationId, userId, username, command.ClarificationFile); var viewModel = await _orchestrator.GetSubcontractorDeclarationViewModel( new GetSubcontractorDeclarationRequest(command.ApplicationId, userId, username)); HydrateSucontractorDeclarationViewModelFromCommand(command, viewModel); if (fileRemovedSuccessfully) { viewModel.ClarificationFile = null; } return(viewModel); }
private async Task <SubcontractorDeclarationViewModel> ProcessSubcontractorDeclarationuploadAndRebuildViewModel(SubmitGatewayPageAnswerCommand command, IFormFileCollection filesToUpload) { var userId = HttpContext.User.UserId(); var username = HttpContext.User.UserDisplayName(); var viewModel = await _orchestrator.GetSubcontractorDeclarationViewModel( new GetSubcontractorDeclarationRequest(command.ApplicationId, userId, username)); HydrateSucontractorDeclarationViewModelFromCommand(command, viewModel); if (filesToUpload != null && filesToUpload.Count > 0) { var fileToUpload = filesToUpload[0].FileName; var fileUploadedSuccessfully = await _applyApiClient.UploadSubcontractorDeclarationClarificationFile(command.ApplicationId, HttpContext.User.UserId(), HttpContext.User.UserDisplayName(), filesToUpload); if (fileUploadedSuccessfully) { viewModel.ClarificationFile = fileToUpload; } } return(viewModel); }
protected async Task <IActionResult> ValidateAndUpdateClarificationPageAnswer <VM>(SubmitGatewayPageAnswerCommand command, Func <Task <VM> > viewModelBuilder, string errorView) where VM : RoatpGatewayPageViewModel { var validationResponse = await GatewayValidator.ValidateClarification(command); if (validationResponse.Errors != null && validationResponse.Errors.Any()) { var viewModel = await viewModelBuilder.Invoke(); viewModel.Status = command.Status; viewModel.OptionFailText = command.OptionFailText; viewModel.OptionInProgressText = command.OptionInProgressText; viewModel.OptionClarificationText = command.OptionClarificationText; viewModel.OptionPassText = command.OptionPassText; viewModel.ClarificationAnswer = command.ClarificationAnswer; viewModel.ErrorMessages = validationResponse.Errors; return(View(errorView, viewModel)); } return(await SubmitGatewayPageAnswerPostClarification(command)); }
public async Task <ValidationResponse> Validate(SubmitGatewayPageAnswerCommand command) { var validationResponse = new ValidationResponse { Errors = new List <ValidationErrorDetail>() }; if (command.OriginalStatus == SectionReviewStatus.Clarification && string.IsNullOrEmpty(command.Status) && command.GatewayReviewStatus == GatewayReviewStatus.InProgress) { validationResponse.Errors.Add(new ValidationErrorDetail("OptionPass", NoSelectionErrorMessages.Errors[command.PageId])); return(await Task.FromResult(validationResponse)); } if (string.IsNullOrWhiteSpace(command.Status)) { validationResponse.Errors.Add(new ValidationErrorDetail("OptionPass", NoSelectionErrorMessages.Errors[command.PageId])); } else { if (command.Status == SectionReviewStatus.Fail && string.IsNullOrEmpty(command.OptionFailText)) { validationResponse.Errors.Add(new ValidationErrorDetail("OptionFailText", FailDetailsRequired)); } else if (command.Status == SectionReviewStatus.Clarification && string.IsNullOrEmpty(command.OptionClarificationText)) { validationResponse.Errors.Add(new ValidationErrorDetail("OptionClarificationText", ClarificationDetailsRequired)); } } if (validationResponse.Errors.Any()) { return(await Task.FromResult(validationResponse)); } switch (command.Status) { case SectionReviewStatus.Pass when !string.IsNullOrEmpty(command.OptionPassText): { var wordCount = command.OptionPassText.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries) .Length; if (wordCount > 150) { validationResponse.Errors.Add(new ValidationErrorDetail("OptionPassText", TooManyWords)); } break; } case SectionReviewStatus.Fail when !string.IsNullOrEmpty(command.OptionFailText): { var wordCount = command.OptionFailText.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries) .Length; if (wordCount > 150) { validationResponse.Errors.Add(new ValidationErrorDetail("OptionFailText", TooManyWords)); } break; } case SectionReviewStatus.InProgress when !string.IsNullOrEmpty(command.OptionInProgressText): { var wordCount = command.OptionInProgressText .Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries) .Length; if (wordCount > 150) { validationResponse.Errors.Add(new ValidationErrorDetail("OptionInProgressText", TooManyWords)); } break; } case SectionReviewStatus.Clarification when !string.IsNullOrEmpty(command.OptionClarificationText): { var wordCount = command.OptionClarificationText .Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries) .Length; if (wordCount > 150) { validationResponse.Errors.Add(new ValidationErrorDetail("OptionClarificationText", TooManyWords)); } break; } } return(await Task.FromResult(validationResponse)); }