コード例 #1
0
        public string Update(CategoryDto category)
        {
            if (!category.IsValid())
            {
                return("Invalid category");
            }

            bool isUpdated = categoryService.Update(category);

            return(isUpdated ? "Category updated successfully." : "Failed to update the category");
        }
コード例 #2
0
        public string Create(CategoryDto category)
        {
            if (!category.IsValid())
            {
                return("Invalid category");
            }

            bool isCreated = categoryService.Create(category);

            return(isCreated ? "Category added successfully." : "Failed to create the category.");
        }
コード例 #3
0
        public IActionResult Create([FromBody] CategoryDto category)
        {
            if (!category.IsValid())
            {
                return(BadRequest());
            }

            if (categoryService.Create(category))
            {
                return(NoContent());
            }

            return(BadRequest());
        }
コード例 #4
0
        public IActionResult Update([FromRoute] int id, [FromBody] CategoryDto category)
        {
            if (!category.IsValid())
            {
                return(BadRequest());
            }

            category.Id = id;

            if (categoryService.Update(category))
            {
                return(NoContent());
            }

            return(BadRequest());
        }