Exemplo n.º 1
0
        public async Task <IActionResult> Put(int id, [FromBody] EditCategoryRequestModel model)
        {
            var exists = await this.categories.CategoryExistsAsync(model.Name);

            if (exists)
            {
                return(BadRequest("Category already exists."));
            }

            return(this.OkOrNotFound(await this.categories.UpdateAsync(id, model.Name)));
        }
Exemplo n.º 2
0
        public IActionResult Put(int id, [FromBody] EditCategoryRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!this.categories.Exists(model.Name))
            {
                return(BadRequest("Category don't exist."));
            }

            var categoryId = this.categories.Edit(
                model.Id,
                model.Name);

            return(Ok(categoryId));
        }