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 IActionResult UpdateBrand([FromBody] BrandDTO brandDTO)
 {
     _logger?.LogInformation($"Inicio del servicio: [PUT] https://localhost:5001/api/brands/brandId ");
     try{
         BrandMapper brandMapper = MapperFactory.CreateBrandMapper();
         Entity      entity      = brandMapper.CreateEntity(brandDTO);
         _logger?.LogInformation($" Se transformó de DTO a Entity ");
         UpdateBrandCommand command = CommandFactory.CreateUpdateBrandCommand((Brand)entity);
         _logger?.LogInformation($" Ejecución del comando ");
         command.Execute();
         if (command.GetResult())
         {
             return(Ok("La modificación fue realizada exitosamente"));
         }
         else
         {
             return(StatusCode(400));
         }
     } 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 (BrandNotFoundException ex) {
         _logger?.LogWarning("La marca con Id : " + ex.BrandId + "no encontrado");
         return(StatusCode(404, ex.Message + ex.BrandId));
     } 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 <BrandDTO> GetBrandById(int brandId)
 {
     _logger?.LogInformation($"Inicio del servicio: [GET] https://localhost:5001/api/brands/brandId ");
     try {
         GetBrandByIdCommand command = CommandFactory.CreateGetBrandByIdCommand(brandId);
         _logger?.LogInformation($" Ejecución del comando ");
         command.Execute();
         BrandMapper brandMapper = MapperFactory.CreateBrandMapper();
         return(Ok(brandMapper.CreateDTO(command.GetResult())));
     } catch (BrandNotFoundException ex) {
         _logger?.LogWarning("La marca con Id : " + ex.BrandId + "no encontrado");
         return(StatusCode(404, ex.Message + ex.BrandId));
     } 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 <IEnumerable <BrandDTO> > GetBrands()
        {
            _logger?.LogInformation($"Inicio del servicio: [GET] https://localhost:5001/api/brands ");
            List <Brand> brands = new List <Brand>();

            try {
                BrandMapper      brandMapper = MapperFactory.CreateBrandMapper();
                GetBrandsCommand command     = CommandFactory.CreateGetBrandsCommand();
                _logger?.LogInformation($" Ejecución del comando ");
                command.Execute();
                return(Ok(brandMapper.CreateDTOList(command.GetResult())));
            } catch (WithoutExistenceOfBrandsException ex) {
                _logger?.LogWarning($"No existen marcas en la base de datos");
                return(StatusCode(404, 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));
            }
        }