public async Task <Unit> Handle(ValidateBulkUploadRecordsCommand command, CancellationToken cancellationToken) { var reservationRequests = command.CsvRecords.Select(response => { Guid.TryParse(command.UserInfo.UserId, out var parsedUserId); return(new ReservationRequest { CourseId = response.CourseCode, AccountLegalEntityId = response.LegalEntityId ?? 0, ProviderId = (uint?)response.ProviderId, RowNumber = response.RowNumber, Id = Guid.NewGuid(), StartDate = GetStartDate(response.StartDateAsString), TransferSenderAccountId = response.TransferSenderId }); }).ToList(); var reservationValidationResult = await _reservationApiClient.PostWithResponseCode <BulkReservationValidationResults>(new PostValidateReservationRequest(command.ProviderId, reservationRequests)); // If any errors this call will throw a bulkupload domain exception, which is handled through middleware. await _apiClient.PostWithResponseCode <object>(new PostValidateBulkUploadRequest(command.ProviderId, new BulkUploadValidateApiRequest { CsvRecords = command.CsvRecords, ProviderId = command.ProviderId, UserInfo = command.UserInfo, BulkReservationValidationResults = reservationValidationResult.Body })); return(Unit.Value); }
public async Task <GetBulkUploadAddDraftApprenticeshipsResult> Handle(BulkUploadAddDraftApprenticeshipsCommand command, CancellationToken cancellationToken) { await Validate(command, cancellationToken); ApiResponse <BulkCreateReservationsWithNonLevyResult> reservationResult = await GetReservations(command); MergeReservationWithDraftApprenticeships(command.BulkUploadAddDraftApprenticeships, reservationResult); var dataToSend = new BulkUploadAddDraftApprenticeshipsRequest { BulkUploadDraftApprenticeships = command.BulkUploadAddDraftApprenticeships, ProviderId = command.ProviderId, UserInfo = command.UserInfo }; var result = await _apiClient.PostWithResponseCode <GetBulkUploadAddDraftApprenticeshipsResponse>( new PostAddDraftApprenticeshipsRequest(command.ProviderId, dataToSend)); result.EnsureSuccessStatusCode(); return(new GetBulkUploadAddDraftApprenticeshipsResult { BulkUploadAddDraftApprenticeshipsResponse = result.Body.BulkUploadAddDraftApprenticeshipsResponse.Select(x => (BulkUploadAddDraftApprenticeshipsResult)x) }); }
public async Task <Unit> Handle(ConfirmCommand request, CancellationToken cancellationToken) { var body = new CreateChangeOfPartyRequestRequest.Body { ChangeOfPartyRequestType = ChangeOfPartyRequestType.ChangeEmployer, NewPartyId = request.AccountLegalEntityId, NewPrice = request.Price, NewStartDate = request.StartDate, NewEndDate = request.EndDate, NewEmploymentEndDate = request.EmploymentEndDate, NewEmploymentPrice = request.EmploymentPrice, DeliveryModel = request.DeliveryModel, UserInfo = request.UserInfo }; var apiRequest = new CreateChangeOfPartyRequestRequest(request.ApprenticeshipId, body); var response = await _commitmentsApiClient.PostWithResponseCode <CreateChangeOfPartyRequestResponse>(apiRequest); response.EnsureSuccessStatusCode(); return(Unit.Value); }