Example #1
0
        public static async Task <ProviderInfo> GetProviderInfoForUkprn(this IProviderInfoCache providerInfoCache, int ukprn)
        {
            if (providerInfoCache == null)
            {
                throw new ArgumentNullException(nameof(providerInfoCache));
            }

            var providerId = await providerInfoCache.GetProviderIdForUkprn(ukprn);

            if (providerId == null)
            {
                return(null);
            }

            return(await providerInfoCache.GetProviderInfo(providerId.Value));
        }
        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
            });
        }