public async Task <IActionResult> Put([FromBody] ChangeCategoryNameDTO model) { var changedCategory = await _categoryService.ChangeCategoryName(model); if (changedCategory.Id == 0) { return(NotFound()); } return(Ok(new { data = changedCategory, success = true })); }
public async Task <CategoryViewModel> ChangeCategoryName(ChangeCategoryNameDTO model) { bool existingCategory = _bookstoreContext.Categories.Any(c => c.Id == model.Id); if (!existingCategory) { return(new CategoryViewModel()); } else { var category = await _bookstoreContext.Categories.FindAsync(model.Id); category.CategoryName = model.CategoryName; _bookstoreContext.Entry(category).State = EntityState.Modified; await _bookstoreContext.SaveChangesAsync(); return(_mapper.Map <CategoryViewModel>(category)); } }