public JsonResult Delete([Bind(Include = "Id")] ComponentDetailVM toBeRemoved) { if (toBeRemoved.Id == 0) { return(Json(new { success = false, ErrorMessage = "Id cannot be zero." })); } try { _componentService.Remove(toBeRemoved); return(Json(new { success = true })); } catch (Exception ex) { if (ex.Message.Contains("Component not found.")) { ModelState.AddModelError(string.Empty, "The delete failed because the component was not found."); } else { ModelState.AddModelError(string.Empty, "The delete failed."); } return(JsonErrorResult()); } }
public ActionResult Add([Bind(Include = "Code,Description,UnitsOfMeasure,QtyOnHand")] ComponentDetailVM componentVM) { if (ModelState.IsValid) { try { _componentService.Add(componentVM); return(Json(new { success = true, model = componentVM })); } catch (Exception ex) { if (ex.Message.Contains("IX_Code")) { ModelState.AddModelError("Code", "This Component Number already exists. Duplicate Component Numbers are not allowed."); } else { ModelState.AddModelError(string.Empty, "The save failed."); } } } return(JsonErrorResult()); }
//public JsonResult Update([Bind(Include = "Id,Code,Description,UnitsOfMeasure,QtyOnHand")]ComponentVM revised) public JsonResult Update(ComponentDetailVM revised) { if (ModelState.IsValid) { try { var updated = _componentService.Update(revised); return(Json(new { success = true, model = updated })); } catch (Exception ex) { if (ex.Message.Contains("IX_Code")) { ModelState.AddModelError("Code", "This Component Number already exists. Duplicate Component Numbers are not allowed."); } else { ModelState.AddModelError(string.Empty, "The save failed."); } } } return(JsonErrorResult()); }