public async Task <AddCohortResult> Handle(AddCohortCommand command, CancellationToken cancellationToken) { var db = _dbContext.Value; var draftApprenticeshipDetails = await _draftApprenticeshipDetailsMapper.Map(command); var cohort = await _cohortDomainService.CreateCohort(command.ProviderId, command.AccountId, command.AccountLegalEntityId, command.TransferSenderId, draftApprenticeshipDetails, command.UserInfo, cancellationToken); db.Cohorts.Add(cohort); await db.SaveChangesAsync(cancellationToken); //this encoding and re-save could be removed and put elsewhere cohort.Reference = _encodingService.Encode(cohort.Id, EncodingType.CohortReference); await db.SaveChangesAsync(cancellationToken); _logger.LogInformation($"Saved cohort. Provider: {command.ProviderId} Account-Legal-Entity:{command.AccountLegalEntityId} Reservation-Id:{command.ReservationId} Commitment-Id:{cohort.Id} Apprenticeship:{cohort.Apprenticeships?.FirstOrDefault()?.Id}"); var response = new AddCohortResult { Id = cohort.Id, Reference = cohort.Reference }; return(response); }
public async Task <Domain.Entities.Reservations.ReservationValidationResult> Validate(ReservationValidationRequest request, CancellationToken cancellationToken) { var mappedRequest = await _requestMapper.Map(request); var result = await _apiClient.ValidateReservation(mappedRequest, cancellationToken); return(await _resultMapper.Map(result)); }
public async Task <IActionResult> Update(long cohortId, long apprenticeshipId, [FromBody] UpdateDraftApprenticeshipRequest request) { var command = await _updateDraftApprenticeshipMapper.Map(request); command.CohortId = cohortId; command.ApprenticeshipId = apprenticeshipId; await _mediator.Send(command); return(Ok()); }
public async Task <IActionResult> GetAll(long cohortId) { var result = await _mediator.Send(new GetDraftApprenticeshipsQuery(cohortId)); var response = await _getDraftApprenticeshipsResultMapper.Map(result); if (response.DraftApprenticeships == null) { return(NotFound()); } return(Ok(response)); }
public async Task <IActionResult> Add(long cohortId, [FromBody] AddDraftApprenticeshipRequest request) { var command = await _addDraftApprenticeshipMapper.Map(request); command.CohortId = cohortId; var result = await _mediator.Send(command); return(Ok(new AddDraftApprenticeshipResponse { DraftApprenticeshipId = result.Id })); }
public async Task <IActionResult> Get(long cohortId, long apprenticeshipId) { var command = new GetDraftApprenticeshipQuery(cohortId, apprenticeshipId); var response = await _mediator.Send(command); if (response == null) { return(NotFound()); } return(Ok(await _getDraftApprenticeshipMapper.Map(response))); }
public async Task <UpdateDraftApprenticeshipResponse> Handle(UpdateDraftApprenticeshipCommand command, CancellationToken cancellationToken) { var draftApprenticeshipDetails = await _draftApprenticeshipDetailsMapper.Map(command); await _cohortDomainService.UpdateDraftApprenticeship(command.CohortId, draftApprenticeshipDetails, command.UserInfo, cancellationToken); _logger.LogInformation($"Saved cohort. Reservation-Id:{command.ReservationId} Commitment-Id:{command.CohortId} Apprenticeship:{command.ApprenticeshipId}"); var response = new UpdateDraftApprenticeshipResponse { Id = command.CohortId, ApprenticeshipId = command.ApprenticeshipId }; return(response); }
public async Task <AddDraftApprenticeshipResult> Handle(AddDraftApprenticeshipCommand request, CancellationToken cancellationToken) { var db = _dbContext.Value; var draftApprenticeshipDetails = await _draftApprenticeshipDetailsMapper.Map(request); var draftApprenticeship = await _cohortDomainService.AddDraftApprenticeship(request.ProviderId, request.CohortId, draftApprenticeshipDetails, request.UserInfo, cancellationToken); await db.SaveChangesAsync(cancellationToken); _logger.LogInformation($"Added draft apprenticeship. Reservation-Id:{request.ReservationId} Commitment-Id:{request.CohortId} Apprenticeship-Id:{draftApprenticeship.Id}"); var response = new AddDraftApprenticeshipResult { Id = draftApprenticeship.Id }; return(response); }