Ejemplo n.º 1
0
        public IActionResult Post([FromBody] CategoryDataTransferObject category)
        {
            var categoryServiceResult = _categoryService.Add(category);

            if (categoryServiceResult.ResponseCode != ResponseCode.Success)
            {
                return(BadRequest(categoryServiceResult.Error));
            }
            return(Ok(categoryServiceResult.Result));
        }
Ejemplo n.º 2
0
        public ServiceResult <CategoryDataTransferObject> Add(CategoryDataTransferObject category)
        {
            var categoryEntity = new Category
            {
                Description = category.Description
            };

            _categoryRepository.Add(categoryEntity);
            _categoryRepository.SaveChanges();
            category.Id = categoryEntity.Id;

            return(ServiceResult <CategoryDataTransferObject> .SuccessResult(category));
        }