public async Task <IActionResult> Submit([FromBody] IEnumerable <SubmitBatchCertificateRequest> batchRequest) { var bag = new List <SubmitBatchCertificateResponse>(); foreach (var request in batchRequest) { var standard = await _mediator.Send(new GetStandardVersionRequest { StandardId = request.GetStandardId() }); if (standard != null) { request.StandardCode = standard.LarsCode; request.StandardReference = standard.IfateReferenceNumber; } var validationResult = await _submitValidator.ValidateAsync(request); var isRequestValid = validationResult.IsValid; var validationErrors = validationResult.Errors.Select(error => error.ErrorMessage).ToList(); SubmitBatchCertificateResponse submitResponse = new SubmitBatchCertificateResponse { RequestId = request.RequestId, ValidationErrors = validationErrors }; if (!validationErrors.Any() && isRequestValid) { submitResponse.Certificate = await _mediator.Send(request); } bag.Add(submitResponse); } return(Ok(bag.ToList())); }
public async Task <IActionResult> Submit([FromBody] IEnumerable <SubmitBatchCertificateRequest> batchRequest) { var bag = new List <SubmitBatchCertificateResponse>(); foreach (var request in batchRequest) { var collatedStandard = request.StandardCode > 0 ? await GetCollatedStandard(request.StandardCode) : await GetCollatedStandard(request.StandardReference); if (collatedStandard != null) { // Only fill in the missing bits... if (request.StandardCode < 1) { request.StandardCode = collatedStandard.StandardId ?? int.MinValue; } else if (string.IsNullOrEmpty(request.StandardReference)) { request.StandardReference = collatedStandard.ReferenceNumber; } } var validationResult = await _submitValidator.ValidateAsync(request); var isRequestValid = validationResult.IsValid; var validationErrors = validationResult.Errors.Select(error => error.ErrorMessage).ToList(); SubmitBatchCertificateResponse submitResponse = new SubmitBatchCertificateResponse { RequestId = request.RequestId, ValidationErrors = validationErrors }; if (!validationErrors.Any() && isRequestValid) { submitResponse.Certificate = await _mediator.Send(request); } bag.Add(submitResponse); } return(Ok(bag.ToList())); }