Esempio n. 1
0
        public async Task <IActionResult> Post([FromBody] CategoryRequestPostModel model)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            int categoryId = await this.categoryService.CreateAsync(model.Name);

            if (categoryId == 0)
            {
                return(BadRequest("There is already a category with that name."));
            }

            return(Ok(categoryId));
        }
Esempio n. 2
0
        public async Task <IActionResult> Put(int id, [FromBody] CategoryRequestPostModel model)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            bool isCategoryExisting = await this.categoryService.IsCategoryExisting(id);

            if (!isCategoryExisting)
            {
                return(NotFound());
            }

            int categoryId = await this.categoryService.EditAsync(id, model.Name);

            if (categoryId == 0)
            {
                return(BadRequest("There is already a category with that name."));
            }

            return(Ok(categoryId));
        }