public async Task <IActionResult> RemoveAndGetOpportunityBasketAsync(int opportunityId, int opportunityItemId) { var opportunityItemCount = await _opportunityService.GetSavedOpportunityItemCountAsync(opportunityId); if (opportunityItemCount == 0) { await _opportunityService.DeleteOpportunityItemAsync(opportunityId, opportunityItemId); return(RedirectToRoute("Start")); } return(RedirectToRoute("GetOpportunityBasket", new { opportunityId, opportunityItemId })); }
public async Task <IActionResult> SavePlacementInformationAsync(PlacementInformationSaveViewModel viewModel) { await Validate(viewModel); if (!ModelState.IsValid) { return(View("PlacementInformation", viewModel)); } var dto = _mapper.Map <PlacementInformationSaveDto>(viewModel); await _opportunityService.UpdateOpportunityItemAsync(dto); if (viewModel.OpportunityType == OpportunityType.ProvisionGap) { await _opportunityService.UpdateProvisionGapAsync(dto); } var opportunityItemCount = await _opportunityService.GetSavedOpportunityItemCountAsync(viewModel.OpportunityId); //if First Opp (saved opportunity items == 0) then LoadWhoIsEmployer else if referral then check answer of if ProvisionGap then OpportunityBasket return(opportunityItemCount == 0 ? RedirectToRoute("GetOpportunityCompanyName", new { viewModel.OpportunityId, viewModel.OpportunityItemId }) : viewModel.OpportunityType == OpportunityType.Referral ? RedirectToRoute("GetCheckAnswers", new { viewModel.OpportunityItemId }) : await SaveCheckAnswers(viewModel.OpportunityId, viewModel.OpportunityItemId)); }
public When_Back_Component_Is_Loaded_With_Saved_Opportunities() { _opportunityService = Substitute.For <IOpportunityService>(); _opportunityService.GetSavedOpportunityItemCountAsync(1).Returns(2); var viewComponent = new BackViewComponent(_opportunityService); _result = viewComponent.InvokeAsync(1, 2).GetAwaiter().GetResult(); }
public async Task <IViewComponentResult> InvokeAsync(int opportunityId, int opportunityItemId) { var viewName = "BackToStart"; var opportunityItemCount = await _opportunityService.GetSavedOpportunityItemCountAsync(opportunityId); if (opportunityItemCount > 0) { viewName = "BackToBasket"; } return(View(viewName, new BackViewModel { OpportunityId = opportunityId, OpportunityItemId = opportunityItemId })); }
public When_Placement_Information_Is_Submitted_Successfully_For_Provision_Gap_And_There_Are_Multiple_Opportunities() { var viewModel = new PlacementInformationSaveViewModel { OpportunityId = 1, OpportunityItemId = 2, OpportunityType = OpportunityType.ProvisionGap, JobRole = "Junior Tester", PlacementsKnown = true, Placements = 3, NoSuitableStudent = true }; var httpContextAccessor = Substitute.For <IHttpContextAccessor>(); var config = new MapperConfiguration(c => { c.AddMaps(typeof(PlacementInformationSaveDtoMapper).Assembly); c.ConstructServicesUsing(type => type.Name.Contains("LoggedInUserEmailResolver") ? new LoggedInUserEmailResolver <PlacementInformationSaveViewModel, PlacementInformationSaveDto>(httpContextAccessor) : type.Name.Contains("LoggedInUserNameResolver") ? (object)new LoggedInUserNameResolver <PlacementInformationSaveViewModel, PlacementInformationSaveDto>(httpContextAccessor) : type.Name.Contains("UtcNowResolver") ? new UtcNowResolver <PlacementInformationSaveViewModel, PlacementInformationSaveDto>(new DateTimeProvider()) : null); }); var mapper = new Mapper(config); _opportunityService = Substitute.For <IOpportunityService>(); _opportunityService.GetSavedOpportunityItemCountAsync(1).Returns(2); var opportunityController = new OpportunityController(_opportunityService, mapper); var controllerWithClaims = new ClaimsBuilder <OpportunityController>(opportunityController) .AddUserName("username") .Build(); httpContextAccessor.HttpContext.Returns(controllerWithClaims.HttpContext); _result = controllerWithClaims.SavePlacementInformationAsync(viewModel).GetAwaiter().GetResult(); }
public When_Placement_Information_Is_Submitted_For_Provision_Gap_With_No_Reason_And_There_Are_No_Search_Results() { _opportunityService = Substitute.For <IOpportunityService>(); _opportunityService.GetSavedOpportunityItemCountAsync(1).Returns(0); var viewModel = new PlacementInformationSaveViewModel { OpportunityId = 1, OpportunityItemId = 2, OpportunityType = OpportunityType.ProvisionGap, SearchResultProviderCount = 0, JobRole = "Junior Tester", PlacementsKnown = false, NoSuitableStudent = false, HadBadExperience = false, ProvidersTooFarAway = false }; var httpContextAccessor = Substitute.For <IHttpContextAccessor>(); var config = new MapperConfiguration(c => { c.AddMaps(typeof(PlacementInformationSaveDtoMapper).Assembly); c.ConstructServicesUsing(type => type.Name.Contains("LoggedInUserEmailResolver") ? new LoggedInUserEmailResolver <PlacementInformationSaveViewModel, PlacementInformationSaveDto>(httpContextAccessor) : type.Name.Contains("LoggedInUserNameResolver") ? (object)new LoggedInUserNameResolver <PlacementInformationSaveViewModel, PlacementInformationSaveDto>(httpContextAccessor) : type.Name.Contains("UtcNowResolver") ? new UtcNowResolver <PlacementInformationSaveViewModel, PlacementInformationSaveDto>(new DateTimeProvider()) : null); }); var mapper = new Mapper(config); _opportunityController = new OpportunityController(_opportunityService, mapper); _result = _opportunityController.SavePlacementInformationAsync(viewModel).GetAwaiter().GetResult(); }
private async Task <CancelViewModel> GetViewModelAsync(int opportunityId, int opportunityItemId) { var viewModel = new CancelViewModel(); if (opportunityId == 0) { return(viewModel); } viewModel.OpportunityId = opportunityId; viewModel.OpportunityItemId = opportunityItemId; var opportunityItemCount = await _opportunityService.GetSavedOpportunityItemCountAsync(opportunityId); if (opportunityItemCount == 0) { return(viewModel); } viewModel.CancelText = "Cancel this opportunity"; return(viewModel); }