示例#1
0
        private ArrivalRequestDTO GetArrivalRequestDtoFromRequest(ArrivalRequest request)
        {
            ArrivalRequestDTO dto = new ArrivalRequestDTO
            {
                Serials     = request.Serials,
                FID         = request.FID,
                ArrivalDate = request.ArrivalDate,
                Comments    = request.Comments
            };

            return(dto);
        }
示例#2
0
        public async Task <IActionResult> Create([FromBody] ArrivalRequest arrivalRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = new ArrivalResponse()
            {
                ResponseResult = new ResponseResult(arrivalRequest.RequestHeader.RequestId)
            };

            try
            {
                ArrivalRequestDTO dto = GetArrivalRequestDtoFromRequest(arrivalRequest);

                var command = new SubmitArrivalCommand(dto,
                                                       JsonConvert.SerializeObject(arrivalRequest),
                                                       arrivalRequest.GetType().Name);

                try
                {
                    var id = await _mediator.Send(command);

                    result.Reference = new ArrivalReferenceResponse
                    {
                        ArrivalNumber = id,
                        ArrivalDate   = dto.ArrivalDate
                    };
                }
                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));
        }