public async Task <ActionResult> Edit(int Id, Subcategory subcategory) { if (ModelState.IsValid && Id.Equals(subcategory.Id)) { try { await _service.Update(subcategory); return(RedirectToAction(nameof(Index))); } catch (ModelValidationException e) { ModelState.AddModelError("SubcategoryValidation", e.Message); return(View(await GetViewModel(subcategory))); } catch (NotFoundException e) { TempData["ErrorMessage"] = e.Message; return(new HttpStatusCodeResult(HttpStatusCode.NotFound, e.Message)); } catch (DbUpdateException e) { TempData["ErrorMessage"] = e.Message; return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message)); } } else { return(View(await GetViewModel(subcategory))); } }
public IHttpActionResult UpdateSubcategory(Subcategory obj) { try { _service.Update(obj); return(Ok()); } catch (ApplicationException e) { return(BadRequest(e.Message)); } }