Exemplo n.º 1
0
        public IActionResult CreateCategory([FromBody] ProductCategoryForCreationDto payload)
        {
            if (payload.Label == payload.Description)
            {
                ModelState.AddModelError("Description", "Label category must be different from description.");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var finalCategory = _mapper
                                .Map <ProductCategory>(payload);

            _categoryService.CreateCategory(finalCategory);

            var createdCategoryToReturn = _mapper
                                          .Map <ProductCategoryDto>(finalCategory);

            return(CreatedAtRoute(
                       "GetCategory",
                       new { id = finalCategory.Id },
                       createdCategoryToReturn));
        }