public IActionResult CreateCategory([FromBody] DTOCreateCategory body)
        {
            try
            {
                var validator        = new CreateCategoryValidation();
                var rusultValidation = validator.Validate(body);
                if (!rusultValidation.IsValid)
                {
                    return(BadRequest(rusultValidation.Errors));
                }

                try
                {
                    var newCategory = _createCategoryService.Execute(body);

                    if (newCategory != null)
                    {
                        var dto = _mapper.Map <DTOCategory>(newCategory);
                        return(Created($"{ControllerContext.HttpContext.Request.Path.Value}", dto));
                    }

                    return(BadRequest("Não foi possivel realizar o cadastro tente novamente."));
                }
                catch (ValidationOnServiceException ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            catch
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ErroMessage));
            }
        }
Ejemplo n.º 2
0
 public CreateCategoryCommand(string name)
 {
     Name      = name;
     validator = new CreateCategoryValidation();
     validator.ValidateName();
 }
Ejemplo n.º 3
0
 public EfCreateCategoryCommand(ProjekatContext context, CreateCategoryValidation validator)
 {
     _context   = context;
     _validator = validator;
 }