Example #1
0
        public async Task <TResponse> Handle(
            TRequest request,
            CancellationToken cancellationToken,
            RequestHandlerDelegate <TResponse> next)
        {
            var courseId   = _descriptor.GetCourseId(request);
            var providerId = await _providerOwnershipCache.GetProviderForCourse(courseId);

            if (providerId == null)
            {
                throw new ResourceDoesNotExistException(ResourceType.Course, courseId);
            }

            if (IsAuthorized(providerId))
            {
                var providerInfo = await _providerInfoCache.GetProviderInfo(providerId.Value);

                _providerContextProvider.SetProviderContext(new ProviderContext(providerInfo));

                return(await next());
            }
            else
            {
                throw new NotAuthorizedException();
            }
        }
Example #2
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var providerId = _providerContextProvider.GetProviderContext().ProviderInfo.ProviderId;

            var qaStatus = await _sqlQueryDispatcher.ExecuteQuery(
                new GetProviderApprenticeshipQAStatus()
            {
                ProviderId = providerId
            });

            var submission = await _sqlQueryDispatcher.ExecuteQuery(
                new GetLatestApprenticeshipQASubmissionForProvider()
            {
                ProviderId = providerId
            });

            var providerInfo = await _providerInfoCache.GetProviderInfo(providerId);

            var vm = new QANotificationsViewModel()
            {
                ProviderType         = providerInfo.ProviderType,
                Status               = qaStatus.ValueOrDefault(),
                HidePassedNotication = submission.Match(none => qaStatus == ApprenticeshipQAStatus.Passed, sub => sub.HidePassedNotification)
            };

            return(View("~/Features/NewApprenticeshipProvider/QANotifications.cshtml", vm));
        }
        public async Task <IActionResult> Confirmed(
            [FromServices] IProviderContextProvider providerContextProvider,
            [FromServices] IProviderInfoCache providerInfoCache,
            ConfirmedQuery request)
        {
            var vm = await _mediator.Send(request);

            var providerInfo = await providerInfoCache.GetProviderInfo(vm.ProviderId);

            providerContextProvider.SetProviderContext(new ProviderContext(providerInfo));

            return(View(vm));
        }
Example #4
0
        private async Task <int> GetUkprnForCourse(Guid courseId)
        {
            var providerId = await _providerOwnershipCache.GetProviderForCourse(courseId);

            if (!providerId.HasValue)
            {
                throw new ResourceDoesNotExistException(ResourceType.Course, courseId);
            }

            var providerInfo = await _providerInfoCache.GetProviderInfo(providerId.Value);

            return(providerInfo.Ukprn);
        }
Example #5
0
        public async Task <OneOf <ModelWithErrors <ViewModel>, ViewModel> > Handle(
            Query request,
            CancellationToken cancellationToken)
        {
            ValidateFlowState();

            var providerId = request.ProviderId;
            var provider   = await _providerInfoCache.GetProviderInfo(providerId);

            ViewModel vm = await CreateViewModel(provider);

            var validator        = new CompleteValidator();
            var validationResult = await validator.ValidateAsync(_flow.State);

            if (!validationResult.IsValid)
            {
                return(new ModelWithErrors <ViewModel>(vm, validationResult));
            }
            else
            {
                return(vm);
            }
        }
        public async Task <ViewModel> Handle(Query request, CancellationToken cancellationToken)
        {
            var providerInfo = await _providerInfoCache.GetProviderInfo(request.ProviderId);

            var results = await _cosmosDbQueryDispatcher.ExecuteQuery(new CosmosQueries.GetAllCoursesForProvider
            {
                ProviderUkprn  = providerInfo.Ukprn,
                CourseStatuses = CourseStatus.BulkUploadReadyToGoLive,
            });

            return(new ViewModel {
                NumberOfCourses = results.SelectMany(c => c.CourseRuns).Count()
            });
        }
Example #7
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));
        }
Example #8
0
        public async Task <TResponse> Handle(
            TRequest request,
            CancellationToken cancellationToken,
            RequestHandlerDelegate <TResponse> next)
        {
            var providerId   = _descriptor.GetProviderId(request);
            var providerInfo = await _providerInfoCache.GetProviderInfo(providerId);

            if (providerInfo == null)
            {
                throw new InvalidStateException(InvalidStateReason.ProviderDoesNotExist);
            }

            if (!providerInfo.ProviderType.HasFlag(_descriptor.ProviderType))
            {
                throw new InvalidStateException(InvalidStateReason.InvalidProviderType);
            }

            return(await next());
        }
Example #9
0
        public async Task <TResponse> Handle(
            TRequest request,
            CancellationToken cancellationToken,
            RequestHandlerDelegate <TResponse> next)
        {
            var providerId  = _descriptor.GetProviderId(request);
            var currentUser = _currentUserProvider.GetCurrentUser();

            if (!AuthorizationRules.CanSubmitQASubmission(currentUser, providerId))
            {
                throw new NotAuthorizedException();
            }

            var qaStatus = await _sqlQueryDispatcher.ExecuteQuery(
                new GetProviderApprenticeshipQAStatus()
            {
                ProviderId = providerId
            });

            var effectiveQaStatus = qaStatus.ValueOrDefault();

            // Ignore UnableToComplete here
            var qaStatusIsValid = (effectiveQaStatus & ~ApprenticeshipQAStatus.UnableToComplete) switch
            {
                ApprenticeshipQAStatus.NotStarted => true,
                ApprenticeshipQAStatus.Failed => true,
                _ => false
            };

            var providerInfo = await _providerInfoCache.GetProviderInfo(providerId);

            var providerTypeIsValid = providerInfo.ProviderType.HasFlag(ProviderType.Apprenticeships);

            if (!qaStatusIsValid || !providerTypeIsValid)
            {
                throw new InvalidStateException(InvalidStateReason.InvalidApprenticeshipQAStatus);
            }

            return(await next());
        }
    }
Example #10
0
        public async Task <ViewModel> Handle(Query request, CancellationToken cancellationToken)
        {
            var provider = await _providerInfoCache.GetProviderInfo(request.ProviderId);

            var results = await _cosmosDbQueryDispatcher.ExecuteQuery(new GetVenuesByProvider { ProviderUkprn = provider.Ukprn });

            return(new ViewModel
            {
                Venues = results.Select(r => new VenueViewModel
                {
                    VenueId = r.Id,
                    VenueName = r.VenueName,
                    AddressParts = new[]
                    {
                        r.AddressLine1,
                        r.AddressLine2,
                        r.Town,
                        r.County
                    }.Where(part => !string.IsNullOrWhiteSpace(part)).ToArray(),
                    PostCode = r.Postcode
                }).ToArray()
            });
        }
        private async Task <int> GetProviderUkprn(Guid providerId)
        {
            var providerInfo = await _providerInfoCache.GetProviderInfo(providerId);

            return(providerInfo.Ukprn);
        }