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); }
private async Task <ApiResponse <BulkCreateReservationsWithNonLevyResult> > GetReservations(BulkUploadAddAndApproveDraftApprenticeshipsCommand command) { var reservationRequests = command.BulkUploadAddAndApproveDraftApprenticeships.Select(x => { var result = (BulkCreateReservations)x; System.Guid.TryParse(command.UserInfo.UserId, out var parsedUserId); result.UserId = parsedUserId; return(result); }).ToList(); var reservationResult = await _reservationApiClient.PostWithResponseCode <BulkCreateReservationsWithNonLevyResult>(new PostBulkCreateReservationRequest(command.ProviderId, reservationRequests)); reservationResult.EnsureSuccessStatusCode(); return(reservationResult); }
private async Task <ApiResponse <BulkCreateReservationsWithNonLevyResult> > GetReservations(BulkUploadAddDraftApprenticeshipsCommand command) { var reservationRequests = command.BulkUploadAddDraftApprenticeships.Select(x => { Guid.TryParse(command.UserInfo.UserId, out var parsedUserId); return(new BulkCreateReservations { CourseId = x.CourseCode, AccountLegalEntityId = x.LegalEntityId ?? 0, ProviderId = (uint?)x.ProviderId, RowNumber = x.RowNumber, Id = Guid.NewGuid(), StartDate = GetStartDate(x.StartDateAsString), TransferSenderAccountId = x.TransferSenderId, ULN = x.Uln }); }).ToList(); var reservationResult = await _reservationApiClient.PostWithResponseCode <BulkCreateReservationsWithNonLevyResult>(new PostBulkCreateReservationRequest(command.ProviderId, reservationRequests)); reservationResult.EnsureSuccessStatusCode(); return(reservationResult); }