예제 #1
0
 private void LocalValidations(EORequestDTO dto)
 {
     dto.Id.ValidateString("El EOID es necesario");
     dto.Name.ValidateObject("El nombre del EO es necesario");
     dto.Address.ValidateObject("La dirección es necesaria");
     dto.ZipCode.ValidateString("El código postal es necesario");
     dto.City.ValidateString("La ciudad es necesaria");
     dto.Country.ValidateString("El país es necesario");
     dto.ActiveFrom.ValidateObject("La fecha es necesaria");
 }
예제 #2
0
        public async Task <IActionResult> Create([FromBody] EORequest eoRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = new EOResponse()
            {
                ResponseResult = new ResponseResult(eoRequest.RequestHeader.RequestId)
            };

            try
            {
                EORequestDTO dto = GetEORequestDtoFromRequest(eoRequest);

                result.Reference = new EOReferenceResponse
                {
                    EONumber = dto.Id,
                };


                var command = new SubmitEOCommand(dto,
                                                  JsonConvert.SerializeObject(eoRequest),
                                                  eoRequest.GetType().Name);

                try
                {
                    var confirmationCode = await _mediator.Send(command);
                }
                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));
        }
예제 #3
0
        private EORequestDTO GetEORequestDtoFromRequest(EORequest request)
        {
            EORequestDTO dto = new EORequestDTO
            {
                Id          = request.Id,
                Description = request.Description,
                ActiveFrom  = request.ActiveFrom,
                Address     = request.Address,
                City        = request.City,
                Country     = request.Country,
                Name        = request.Name,
                ZipCode     = request.ZipCode
            };

            return(dto);
        }
예제 #4
0
        public async Task <string> Handle(UpdateEOCommand request, CancellationToken cancellationToken)
        {
            EORequestDTO dto = request.Request;

            try
            {
                dto.ValidateObject("La request no puede ser null");
                LocalValidations(dto);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            var eo = new EconomicOperators();

            try
            {
                eo = new EconomicOperators
                {
                    Id          = dto.Id,
                    Name        = dto.Name,
                    Description = dto.Description,
                    Address     = dto.Address,
                    ZipCode     = dto.ZipCode,
                    City        = dto.City,
                    Country     = dto.Country,
                    ActiveFrom  = dto.ActiveFrom
                };
            }
            catch
            {
                throw new Exception("Error al formatear el EO");
            }

            try
            {
                var added = _eoRepository.Add(eo).Result;
                return(added);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }