public async Task <ValidateReservationResponse> Handle(ValidateReservationRequest request) { var apprenticeship = await _apprenticeshipRepository.GetApprenticeship(request.ApprenticeshipId); var validationServiceRequest = new ReservationValidationServiceRequest { AccountId = apprenticeship.EmployerAccountId, ApprenticeshipId = request.ApprenticeshipId, ReservationId = apprenticeship.ReservationId, CommitmentId = apprenticeship.CommitmentId, TrainingCode = request.CourseCode ?? apprenticeship.TrainingCode, StartDate = request.StartDate ?? apprenticeship.StartDate, ProviderId = apprenticeship.ProviderId }; var validationResult = await _reservationValidationService.CheckReservation(validationServiceRequest); return(new ValidateReservationResponse { ReservationValidationResult = validationResult }); }
private async Task CheckReservation(ApprenticeshipUpdate pendingUpdate, Apprenticeship originalApprenticeship) { var request = new ReservationValidationServiceRequest { AccountId = originalApprenticeship.EmployerAccountId, ApprenticeshipId = originalApprenticeship.Id, ReservationId = originalApprenticeship.ReservationId, CommitmentId = originalApprenticeship.CommitmentId, TrainingCode = pendingUpdate.TrainingCode ?? originalApprenticeship.TrainingCode, StartDate = pendingUpdate.StartDate ?? originalApprenticeship.StartDate, ProviderId = originalApprenticeship.ProviderId }; var validationResult = await _reservationValidationService.CheckReservation(request); if (validationResult.HasErrors) { var validationFailures = validationResult.ValidationErrors.Select(e => new ValidationFailure(e.PropertyName, e.Reason)); throw new ValidationException(validationFailures); } }