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))); }
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)); }