public async Task <ActionResult> SetLegalEntity(SelectLegalEntityViewModel selectedLegalEntity) { var response = await _modelMapper.Map <LegalEntitySignedAgreementViewModel>(selectedLegalEntity); if (response.HasSignedMinimumRequiredAgreementVersion) { return(RedirectToAction("SelectProvider", new SelectProviderRequest { AccountHashedId = selectedLegalEntity.AccountHashedId, TransferSenderId = selectedLegalEntity.TransferConnectionCode, AccountLegalEntityHashedId = response.AccountLegalEntityPublicHashedId, EncodedPledgeApplicationId = selectedLegalEntity.EncodedPledgeApplicationId })); } return(RedirectToAction("AgreementNotSigned", new LegalEntitySignedAgreementViewModel { AccountHashedId = selectedLegalEntity.AccountHashedId, LegalEntityId = selectedLegalEntity.LegalEntityId, CohortRef = selectedLegalEntity.CohortRef, LegalEntityName = response.LegalEntityName, AccountLegalEntityPublicHashedId = response.AccountLegalEntityPublicHashedId, EncodedPledgeApplicationId = selectedLegalEntity.EncodedPledgeApplicationId })); }
public void And_Api_LegalEntities_Null_Then_Sets_LegalEntities_Null( ReservationsRouteModel routeModel) { var viewModel = new SelectLegalEntityViewModel(routeModel, null, null); viewModel.LegalEntities.Should().BeNull(); }
public void Then_Sets_RouteModel( ReservationsRouteModel routeModel, List <AccountLegalEntity> accountLegalEntities) { var viewModel = new SelectLegalEntityViewModel(routeModel, accountLegalEntities, null); viewModel.RouteModel.Should().Be(routeModel); }
public void Then_Sets_LegalEntities( ReservationsRouteModel routeModel, List <AccountLegalEntity> accountLegalEntities) { var legalEntity = accountLegalEntities.First(); var expectedLegalEntityPublicHashedId = legalEntity.AccountLegalEntityPublicHashedId; var viewModel = new SelectLegalEntityViewModel(routeModel, accountLegalEntities, expectedLegalEntityPublicHashedId); viewModel.LegalEntities.Should().BeEquivalentTo(accountLegalEntities, option => option.ExcludingMissingMembers()); viewModel.LegalEntities.First(c => c.AccountLegalEntityPublicHashedId.Equals(expectedLegalEntityPublicHashedId)).Selected.Should().BeTrue(); }
public async Task <IActionResult> PostSelectLegalEntity(ReservationsRouteModel routeModel, ConfirmLegalEntityViewModel viewModel) { try { if (!ModelState.IsValid) { var legalEntitiesResponse = await _mediator.Send(new GetLegalEntitiesQuery { AccountId = _encodingService.Decode(routeModel.EmployerAccountId, EncodingType.AccountId) }); var requestViewModel = new SelectLegalEntityViewModel(routeModel, legalEntitiesResponse.AccountLegalEntities, viewModel.LegalEntity); return(View("SelectLegalEntity", requestViewModel)); } var decodedAccountId = _encodingService.Decode(routeModel.EmployerAccountId, EncodingType.AccountId); var response = await _mediator.Send(new GetLegalEntitiesQuery { AccountId = decodedAccountId }); var selectedAccountLegalEntity = response.AccountLegalEntities.Single(model => model.AccountLegalEntityPublicHashedId == viewModel.LegalEntity); if (!selectedAccountLegalEntity.AgreementSigned) { return(RedirectToSignAgreement(routeModel, RouteNames.EmployerSelectLegalEntity)); } await CacheReservation(routeModel, selectedAccountLegalEntity); return(RedirectToRoute(RouteNames.EmployerSelectCourse, routeModel)); } catch (ValidationException e) { foreach (var member in e.ValidationResult.MemberNames) { ModelState.AddModelError(member.Split('|')[0], member.Split('|')[1]); } var legalEntitiesResponse = await _mediator.Send(new GetLegalEntitiesQuery { AccountId = _encodingService.Decode(routeModel.EmployerAccountId, EncodingType.AccountId) }); var requestViewModel = new SelectLegalEntityViewModel(routeModel, legalEntitiesResponse.AccountLegalEntities, viewModel.LegalEntity); return(View("SelectLegalEntity", requestViewModel)); } catch (ReservationLimitReachedException) { return(View("ReservationLimitReached", GenerateLimitReachedBackLink(routeModel))); } catch (GlobalReservationRuleException) { return(View("EmployerFundingPaused")); } }
public void Arrange() { var autoFixture = new Fixture(); _employerAccountsService = new Mock <IEmployerAccountsService>(); _selectLegalEntityViewModel = autoFixture.Create <SelectLegalEntityViewModel>(); var legalEntity = autoFixture.Create <LegalEntity>(); legalEntity.Id = _selectLegalEntityViewModel.LegalEntityId; _employerAccountsService.Setup(x => x.GetLegalEntitiesForAccount(_selectLegalEntityViewModel.AccountHashedId)) .ReturnsAsync(new List <LegalEntity> { legalEntity }); _mapper = new SelectedLegalEntityToSignedAgreementViewModelMapper(_employerAccountsService.Object); }
public async Task <IActionResult> SelectLegalEntity(ReservationsRouteModel routeModel) { try { GetCachedReservationResult cachedResponse = null; if (routeModel.Id.HasValue) { cachedResponse = await _mediator.Send(new GetCachedReservationQuery { Id = routeModel.Id.Value }); } var legalEntitiesResponse = await _mediator.Send(new GetLegalEntitiesQuery { AccountId = _encodingService.Decode(routeModel.EmployerAccountId, EncodingType.AccountId) }); if (legalEntitiesResponse.AccountLegalEntities.Count() == 1) { var accountLegalEntity = legalEntitiesResponse.AccountLegalEntities.First(); if (!accountLegalEntity.AgreementSigned) { return(RedirectToSignAgreement(routeModel, RouteNames.EmployerIndex)); } await CacheReservation(routeModel, accountLegalEntity, true); return(RedirectToRoute(RouteNames.EmployerSelectCourse, routeModel)); } var viewModel = new SelectLegalEntityViewModel(routeModel, legalEntitiesResponse.AccountLegalEntities, cachedResponse?.AccountLegalEntityPublicHashedId); return(View("SelectLegalEntity", viewModel)); } catch (ReservationLimitReachedException) { return(View("ReservationLimitReached", GenerateLimitReachedBackLink(routeModel))); } catch (GlobalReservationRuleException) { return(View("EmployerFundingPaused", GenerateLimitReachedBackLink(routeModel))); } catch (Exception e) { _logger.LogError(e, e.Message); return(RedirectToRoute(RouteNames.Error500)); } }
public void Arrange() { var autoFixture = new Fixture(); _modelMapper = new Mock <IModelMapper>(); _linkGenerator = new Mock <ILinkGenerator>(); _chooseOrganisationRequest = autoFixture.Create <SelectLegalEntityRequest>(); _selectLegalEntityViewModel = autoFixture.Create <SelectLegalEntityViewModel>(); _modelMapper.Setup(x => x.Map <SelectLegalEntityViewModel>(It.Is <SelectLegalEntityRequest>(r => r == _chooseOrganisationRequest))) .ReturnsAsync(_selectLegalEntityViewModel); _controller = new CohortController(Mock.Of <ICommitmentsApiClient>(), Mock.Of <ILogger <CohortController> >(), _linkGenerator.Object, _modelMapper.Object, Mock.Of <IAuthorizationService>(), Mock.Of <IEncodingService>()); }
public async Task <ActionResult> SetLegalEntity(string hashedAccountId, SelectLegalEntityViewModel selectedLegalEntity) { if (!ModelState.IsValid) { var response = await _employerCommitmentsOrchestrator.GetLegalEntities(hashedAccountId, selectedLegalEntity.CohortRef, OwinWrapper.GetClaimValue(@"sub")); return(View("SelectLegalEntity", response)); } var agreement = await _employerCommitmentsOrchestrator.GetLegalEntitySignedAgreementViewModel(hashedAccountId, selectedLegalEntity.LegalEntityCode, selectedLegalEntity.CohortRef); if (agreement.Data.HasSignedAgreement) { return(RedirectToAction("SearchProvider", selectedLegalEntity)); } else { return(RedirectToAction("AgreementNotSigned", agreement.Data)); } }