public async Task <IActionResult> Create([FromBody] DispatchRequest dispatchRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = new DispatchResponse() { ResponseResult = new ResponseResult(dispatchRequest.RequestHeader.RequestId) }; try { DispatchRequestDTO dto = GetDispatchRequestDtoFromRequest(dispatchRequest); var command = new SubmitDispatchCommand(dto, JsonConvert.SerializeObject(dispatchRequest), dispatchRequest.GetType().Name); try { var id = await _mediator.Send(command); result.Reference = new DispatchReferenceResponse { DispatchNumber = id, DispatchDate = dto.DispatchDate }; } catch (Exception ex) { throw new Exception(ex.Message); } } catch (Exception e) { result.ResponseResult.Errors = new List <ErrorDetail>() { new ErrorDetail() { ErrorCode = "-1", ErrorMessage = e.Message } }; return(BadRequest(result)); } return(Ok(result)); }
private DispatchRequestDTO GetDispatchRequestDtoFromRequest(DispatchRequest request) { DispatchRequestDTO dto = new DispatchRequestDTO { Serials = request.Serials, FID = request.Facility, DispatchDate = request.DispatchDate, DestinationEU = request.DestinationEU, DestinationFID = request.DestinationFacility, DestinationName = request.DestinationName, DestinationCountry = request.DestinationCountry, DestinationAddress = request.DestinationAddress, DestinationCity = request.DestinationCity, DestinationZipCode = request.DestinationZipCode, TransportMode = request.TransportMode, Vehicle = request.Vehicle }; return(dto); }