예제 #1
0
        public async Task <Unit> Handle(CacheReservationStartDateCommand command, CancellationToken cancellationToken)
        {
            var queryValidationResult = await _validator.ValidateAsync(command);

            if (!queryValidationResult.IsValid())
            {
                throw new ValidationException(queryValidationResult.ConvertToDataAnnotationsValidationResult(), null, null);
            }

            CachedReservation cachedReservation;

            if (!command.UkPrn.HasValue)
            {
                cachedReservation = await _cachedReservationRepository.GetEmployerReservation(command.Id);
            }
            else
            {
                cachedReservation = await _cachedReservationRepository.GetProviderReservation(command.Id, command.UkPrn.Value);
            }

            if (cachedReservation == null)
            {
                throw new CachedReservationNotFoundException(command.Id);
            }

            cachedReservation.TrainingDate = command.TrainingDate;

            await _cacheStorageService.SaveToCache(command.Id.ToString(), cachedReservation, 1);

            return(Unit.Value);
        }
예제 #2
0
        public async Task <CreateReservationResult> Handle(CreateReservationCommand command, CancellationToken cancellationToken)
        {
            var queryValidationResult = await _createReservationValidator.ValidateAsync(command);

            if (!queryValidationResult.IsValid())
            {
                throw new ValidationException(queryValidationResult.ConvertToDataAnnotationsValidationResult(), null, null);
            }

            CachedReservation cachedReservation;

            if (!command.UkPrn.HasValue)
            {
                cachedReservation = await _cachedReservationRepository.GetEmployerReservation(command.Id);
            }
            else
            {
                cachedReservation = await _cachedReservationRepository.GetProviderReservation(command.Id, command.UkPrn.Value);
            }

            if (cachedReservation == null)
            {
                throw new CachedReservationNotFoundException(command.Id);
            }

            var createValidationResult = await _cachedReservationValidator.ValidateAsync(cachedReservation);

            if (!createValidationResult.IsValid())
            {
                throw new ValidationException(createValidationResult.ConvertToDataAnnotationsValidationResult(), null, null);
            }

            var apiRequest = new ReservationApiRequest(
                _apiOptions.Value.Url,
                cachedReservation.AccountId,
                cachedReservation.IsEmptyCohortFromSelect ? null : cachedReservation.UkPrn,
                new DateTime(cachedReservation.TrainingDate.StartDate.Year, cachedReservation.TrainingDate.StartDate.Month, 1),
                cachedReservation.Id,
                cachedReservation.AccountLegalEntityId,
                cachedReservation.AccountLegalEntityName,
                cachedReservation.CourseId,
                command.UserId);

            var response = await _apiClient.Create <CreateReservationResponse>(apiRequest);

            await _cacheStorageService.DeleteFromCache(command.Id.ToString());

            return(new CreateReservationResult
            {
                Id = response.Id,
                AccountLegalEntityPublicHashedId = cachedReservation.AccountLegalEntityPublicHashedId,
                CohortRef = cachedReservation.CohortRef,
                IsEmptyCohortFromSelect = cachedReservation.IsEmptyCohortFromSelect,
                ProviderId = cachedReservation.UkPrn,
                JourneyData = cachedReservation.JourneyData
            });
        }
        public async Task <Unit> Handle(CacheReservationCourseCommand command, CancellationToken cancellationToken)
        {
            var validationResult = await _validator.ValidateAsync(command);

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

            CachedReservation cachedReservation;

            if (!command.UkPrn.HasValue)
            {
                cachedReservation = await _cachedReservationRepository.GetEmployerReservation(command.Id);
            }
            else
            {
                cachedReservation = await _cachedReservationRepository.GetProviderReservation(command.Id, command.UkPrn.Value);
            }

            if (cachedReservation == null)
            {
                throw new CachedReservationNotFoundException(command.Id);
            }

            if (string.IsNullOrEmpty(command.SelectedCourseId))
            {
                var course = new Course(null, null, 0);
                cachedReservation.CourseId          = course.Id;
                cachedReservation.CourseDescription = course.CourseDescription;
            }
            else
            {
                var course = await _courseService.GetCourse(command.SelectedCourseId);

                cachedReservation.CourseId          = course.Id;
                cachedReservation.CourseDescription = course.CourseDescription;
            }

            await _cacheStorageService.SaveToCache(cachedReservation.Id.ToString(), cachedReservation, 1);

            return(Unit.Value);
        }
예제 #4
0
        public async Task <GetCachedReservationResult> Handle(GetCachedReservationQuery request, CancellationToken cancellationToken)
        {
            var validationResult = await _validator.ValidateAsync(request);

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

            CachedReservation cachedReservation;

            if (request.UkPrn != default(uint))
            {
                cachedReservation =
                    await _cachedReservationRepository.GetProviderReservation(request.Id, request.UkPrn);
            }
            else
            {
                cachedReservation =
                    await _cachedReservationRepository.GetEmployerReservation(request.Id);
            }

            return(new GetCachedReservationResult
            {
                Id = cachedReservation.Id,
                AccountId = cachedReservation.AccountId,
                AccountLegalEntityId = cachedReservation.AccountLegalEntityId,
                AccountLegalEntityName = cachedReservation.AccountLegalEntityName,
                AccountLegalEntityPublicHashedId = cachedReservation.AccountLegalEntityPublicHashedId,
                CourseId = cachedReservation.CourseId,
                CourseDescription = cachedReservation.CourseDescription,
                TrainingDate = cachedReservation.TrainingDate,
                AccountName = cachedReservation.AccountName,
                CohortRef = cachedReservation.CohortRef,
                EmployerHasSingleLegalEntity = cachedReservation.EmployerHasSingleLegalEntity,
                IsEmptyCohortFromSelect = cachedReservation.IsEmptyCohortFromSelect,
                UkPrn = cachedReservation.UkPrn
            });
        }