public async Task <ActionResult> UpdateCategory(string id, Category category) { try { var categoryToUpdate = await repo.GetById(id); if (categoryToUpdate == null) { return(NotFound($"Category with Id = {id} not found")); } category.CategoryId = id; var result = await repo.Edit(category); if (result) { return(Ok()); } return(BadRequest()); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, $"Error updating data. Error message:{e.Message}")); } }
public IActionResult Edit(CategoryWriteDTO category) { if (category != null) { if (category.parent_id != null) { category.parent = _repo.GetOneById(category.parent_id); } Category cat = _mapper.Map <Category>(category); _repo.Edit(cat); if (_repo.SaveChanges() > 0) { return(Ok("updated")); } } return(BadRequest()); }
public IHttpActionResult Edit(int id, string name) { var category = _categoryRepo.Edit(id, name); return(Ok(category)); }