Ejemplo n.º 1
0
        public async Task <GetCourseEpaoResult> Handle(GetCourseEpaoQuery request, CancellationToken cancellationToken)
        {
            var validationResult = await _validator.ValidateAsync(request);

            if (!validationResult.IsValid())
            {
                throw new ValidationException(validationResult.DataAnnotationResult, null, null);
            }

            var epaoTask        = _assessorsApiClient.Get <GetEpaoResponse>(new GetEpaoRequest(request.EpaoId));
            var courseEpaosTask = _assessorsApiClient.GetAll <GetCourseEpaoListItem>(
                new GetCourseEpaosRequest {
                CourseId = request.CourseId
            });
            var epaoCoursesTask = _assessorsApiClient.GetAll <GetEpaoCourseListItem>(new GetEpaoCoursesRequest(request.EpaoId));
            var areasTask       = _cachedDeliveryAreasService.GetDeliveryAreas();
            var coursesTask     = _cachedCoursesService.GetCourses();

            await Task.WhenAll(epaoTask, courseEpaosTask, epaoCoursesTask, areasTask, coursesTask);

            if (epaoTask.Result == default)
            {
                throw new NotFoundException <GetCourseEpaoResult>();
            }

            var filteredCourseEpaos = courseEpaosTask.Result
                                      .Where(_courseEpaoIsValidFilterService.IsValidCourseEpao)
                                      .ToList();

            if (!filteredCourseEpaos.Any(item => string.Equals(item.EpaoId,
                                                               request.EpaoId, StringComparison.CurrentCultureIgnoreCase)))
            {
                _logger.LogInformation($"Course [{request.CourseId}], EPAO [{request.EpaoId}] not active.");
                throw new NotFoundException <GetCourseEpaoResult>();
            }

            var courseEpao = filteredCourseEpaos.Single(item =>
                                                        string.Equals(item.EpaoId, request.EpaoId, StringComparison.CurrentCultureIgnoreCase));

            var filterAdditionalCourses = epaoCoursesTask.Result
                                          .Where(x => _courseEpaoIsValidFilterService.ValidateEpaoStandardDates(x.DateStandardApprovedOnRegister,
                                                                                                                x.EffectiveTo, x.EffectiveFrom)).ToList();
            var allCourses = coursesTask.Result.Standards
                             .Where(course => filterAdditionalCourses
                                    .Any(item => item.StandardCode == course.LarsCode));

            return(new GetCourseEpaoResult
            {
                Epao = epaoTask.Result,
                Course = coursesTask.Result.Standards.Single(item => item.LarsCode == request.CourseId),
                EpaoDeliveryAreas = courseEpao.DeliveryAreas,
                CourseEpaosCount = filteredCourseEpaos.Count,
                DeliveryAreas = areasTask.Result,
                EffectiveFrom = courseEpao.CourseEpaoDetails.EffectiveFrom !.Value,
                AllCourses = allCourses
            });
Ejemplo n.º 2
0
        public async Task <GetCourseEpaosResult> Handle(GetCourseEpaosQuery request, CancellationToken cancellationToken)
        {
            var epaosTask = _assessorsApiClient.GetAll <GetCourseEpaoListItem>(
                new GetCourseEpaosRequest
            {
                CourseId = request.CourseId
            });

            var courseTask = _coursesApiClient.Get <GetStandardsListItem>(
                new GetStandardRequest(request.CourseId));

            await Task.WhenAll(epaosTask, courseTask);

            _logger.LogDebug($"Found [{epaosTask.Result.Count()}] EPAOs for Course Id:[{request.CourseId}].");

            var filteredEpaos = epaosTask.Result
                                .Where(_courseEpaoIsValidFilterService.IsValidCourseEpao)
                                .ToList();

            var epaoTasks = filteredEpaos.
                            ToDictionary(
                t => t.EpaoId,
                t => _assessorsApiClient.Get <IEnumerable <GetStandardsExtendedListItem> >(
                    new GetCourseEpaosStandardVersionsRequest(t.EpaoId, request.CourseId)));

            await Task.WhenAll(epaoTasks.Select(x => x.Value).ToArray());

            foreach (var filtEpao in filteredEpaos)
            {
                if (epaoTasks.TryGetValue(filtEpao.EpaoId, out var epaoResponse) && epaoResponse.Result != null)
                {
                    var epaoVersions = epaoResponse.Result
                                       .Where(c => _courseEpaoIsValidFilterService.ValidateVersionDates(c.DateVersionApproved, c.EffectiveFrom, c.EffectiveTo))
                                       .Select(x => x.Version).ToArray();

                    filtEpao.CourseEpaoDetails.StandardVersions = epaoVersions;
                }
            }

            _logger.LogDebug($"Found [{filteredEpaos.Count}] EPAOs for Course Id:[{request.CourseId}] after filtering.");

            return(new GetCourseEpaosResult
            {
                Epaos = filteredEpaos.Where(x => x.CourseEpaoDetails.StandardVersions.Length > 0)
                        .OrderBy(item => item.Name),
                Course = courseTask.Result
            });
        }
Ejemplo n.º 3
0
        public async Task <GetEpaoResult> Handle(GetEpaoQuery request, CancellationToken cancellationToken)
        {
            var validationResult = await _validator.ValidateAsync(request);

            if (!validationResult.IsValid())
            {
                throw new ValidationException(validationResult.DataAnnotationResult, null, null);
            }

            var apiRequest = new GetEpaoRequest(request.EpaoId);
            var apiResult  = await _assessorsApiClient.Get <GetEpaoResponse>(apiRequest);

            if (apiResult == default)
            {
                throw new NotFoundException <GetEpaoResult>();
            }

            return(new GetEpaoResult {
                Epao = apiResult
            });
        }