public async Task <OneOf <ModelWithErrors <ViewModel>, Success> > Handle( Command request, CancellationToken cancellationToken) { ThrowIfFlowStateNotValid(); var tLevelId = Guid.NewGuid(); var currentUser = _currentUserProvider.GetCurrentUser(); var now = _clock.UtcNow; var result = await _sqlQueryDispatcher.ExecuteQuery( new CreateTLevel() { CreatedBy = currentUser, CreatedOn = now, EntryRequirements = _journeyInstance.State.EntryRequirements, HowYoullBeAssessed = _journeyInstance.State.HowYoullBeAssessed, HowYoullLearn = _journeyInstance.State.HowYoullLearn, LocationVenueIds = _journeyInstance.State.LocationVenueIds, ProviderId = request.ProviderId, StartDate = _journeyInstance.State.StartDate.Value, TLevelDefinitionId = _journeyInstance.State.TLevelDefinitionId.Value, TLevelId = tLevelId, Website = _journeyInstance.State.Website, WhatYouCanDoNext = _journeyInstance.State.WhatYouCanDoNext, WhatYoullLearn = _journeyInstance.State.WhatYoullLearn, WhoFor = _journeyInstance.State.WhoFor, YourReference = _journeyInstance.State.YourReference }); if (result.Value is CreateTLevelFailedReason reason) { if (reason == CreateTLevelFailedReason.TLevelAlreadyExistsForDate) { var vm = await CreateViewModel(); var validationResult = new ValidationResult(new[] { new ValidationFailure( nameof(ViewModel.StartDate), "T Level already exists, enter a new start date") }); return(new ModelWithErrors <ViewModel>(vm, validationResult)); } throw new NotImplementedException( $"Unknown {nameof(CreateTLevelFailedReason)}: '{reason}'."); } _journeyInstance.UpdateState(state => state.SetCreatedTLevel(tLevelId)); // Complete JourneyInstance so state can no longer be changed _journeyInstance.Complete(); return(new Success()); }
public async Task <OneOf <ModelWithErrors <ViewModel>, SuccessViewModel> > Handle(Command request, CancellationToken cancellationToken) { var ukprn = await GetUkprnForCourse(request.CourseId); var(course, courseRun) = await GetCourseAndCourseRun(request.CourseId, request.CourseRunId, ukprn); if (!request.Confirm) { var vm = await CreateViewModel(course, courseRun); var validationResult = new ValidationResult(new[] { new ValidationFailure(nameof(request.Confirm), "Confirm you want to delete the course") }); return(new ModelWithErrors <ViewModel>(vm, validationResult)); } await _cosmosDbQueryDispatcher.ExecuteQuery(new DeleteCourseRunQuery() { CourseId = request.CourseId, CourseRunId = request.CourseRunId, ProviderUkprn = ukprn, UpdatedBy = _currentUserProvider.GetCurrentUser().UserId, UpdatedDate = _clock.UtcNow, }); // The next page needs this info - stash it in the JourneyModel // since it will no longer able to query for it. _journeyInstance.UpdateState(new JourneyModel() { CourseName = courseRun.CourseName, ProviderId = (await _providerInfoCache.GetProviderIdForUkprn(ukprn)).Value, ProviderUkprn = ukprn }); _journeyInstance.Complete(); return(new SuccessViewModel() { CourseId = request.CourseId, CourseRunId = request.CourseRunId, CourseName = courseRun.CourseName }); }
public async Task <OneOf <ModelWithErrors <ViewModel>, Success> > Handle(Command request, CancellationToken cancellationToken) { _journeyInstance.ThrowIfCompleted(); var apprenticeship = await GetApprenticeship(request.ApprenticeshipId); if (!request.Confirm) { var vm = CreateViewModel(apprenticeship); var validationResult = new ValidationResult(new[] { new ValidationFailure(nameof(request.Confirm), "Confirm you want to delete the Apprenticeship") }); return(new ModelWithErrors <ViewModel>(vm, validationResult)); } await _sqlQueryDispatcher.ExecuteQuery(new DeleteApprenticeshipQuery() { ApprenticeshipId = request.ApprenticeshipId, DeletedBy = _currentUserProvider.GetCurrentUser(), DeletedOn = _clock.UtcNow }); _providerOwnershipCache.OnApprenticeshipDeleted(request.ApprenticeshipId); // The next page needs this info - stash it in the JourneyModel // since it will no longer able to query for it. _journeyInstance.UpdateState(new JourneyModel() { ApprenticeshipId = apprenticeship.ApprenticeshipId, ProviderId = apprenticeship.ProviderId, ApprenticeshipTitle = apprenticeship.Standard.StandardName, NotionalNVQLevelv2 = apprenticeship.Standard.NotionalNVQLevelv2 }); _journeyInstance.Complete(); return(new Success()); }
public async Task <OneOf <ModelWithErrors <ViewModel>, Success> > Handle(Command request, CancellationToken cancellationToken) { _journeyInstance.ThrowIfCompleted(); var tLevel = await GetTLevel(request.TLevelId); if (!request.Confirm) { var vm = CreateViewModel(tLevel); var validationResult = new ValidationResult(new[] { new ValidationFailure(nameof(request.Confirm), "Confirm you want to delete the T Level") }); return(new ModelWithErrors <ViewModel>(vm, validationResult)); } await _sqlQueryDispatcher.ExecuteQuery(new DeleteTLevelQuery() { TLevelId = request.TLevelId, DeletedBy = _currentUserProvider.GetCurrentUser(), DeletedOn = _clock.UtcNow }); _providerOwnershipCache.OnTLevelDeleted(request.TLevelId); // The next page needs this info - stash it in the JourneyModel // since it will no longer able to query for it. _journeyInstance.UpdateState(new JourneyModel() { TLevelName = tLevel.TLevelDefinition.Name, ProviderId = tLevel.ProviderId, YourReference = tLevel.YourReference }); _journeyInstance.Complete(); return(new Success()); }