public IActionResult AddBrand([FromBody] BrandDTO brandDTO) { _logger?.LogInformation($"Inicio del servicio: [Post] https://localhost:5001/api/brands "); try { BrandMapper brandMapper = MapperFactory.CreateBrandMapper(); Entity entity = brandMapper.CreateEntity(brandDTO); _logger?.LogInformation($" Se transformó de DTO a Entity "); AddBrandCommand command = CommandFactory.CreateAddBrandCommand((Brand)entity); _logger?.LogInformation($" Ejecución del comando "); command.Execute(); return(Ok("ok " + command.GetResult())); } catch (RequiredAttributeException ex) { _logger?.LogWarning("Atributo requerido: " + ex.Message); return(StatusCode(400, ex.Message)); } catch (UniqueAttributeException ex) { _logger?.LogWarning(ex.Message); return(StatusCode(500, ex.Message)); } catch (InternalServerErrorException ex) { _logger?.LogError("Error: " + ex.Ex.Message); return(StatusCode(500, ex.Message)); } catch (Exception) { _logger?.LogError("Error inesperado"); return(StatusCode(400)); } }
public ActionResult Create(BrandViewModel brandViewModel) { if(ModelState.IsValid) { var addBrandCommand = new AddBrandCommand(); Mapper.CreateMap<BrandViewModel, AddBrandCommand>(); Mapper.Map(brandViewModel, addBrandCommand); CommandProcessor.Process<AddBrandCommand, CommandResult>(addBrandCommand, ModelState); if (!ModelState.IsValid) return View(); return this.RedirectToAction(c => c.Index(null, null)); } return View(); }