public JsonResult Delete([Bind(Include = "Id")] ToolDetailVM toBeRemoved) { if (toBeRemoved.Id == 0) { return(Json(new { success = false, ErrorMessage = "Id cannot be zero." })); } try { _toolService.Remove(toBeRemoved); return(Json(new { success = true })); } catch (Exception ex) { if (ex.Message.Contains("Tool not found.")) { ModelState.AddModelError(string.Empty, "The delete failed because the tool was not found."); } else { ModelState.AddModelError(string.Empty, "The delete failed."); } return(JsonErrorResult()); } }
//Certification for selected Tool public IActionResult Details(int id) { Tool tool = db.Tools.Include(x => x.Certification).ThenInclude(x => x.OperatorCertifications).ThenInclude(x => x.Oper).FirstOrDefault(x => x.ToolId == id); //Certification certification = db.Certifications.FirstOrDefault(x => x.CertificationId == tool.CertificationId); ToolDetailVM VM = new ToolDetailVM(tool); return(View(VM)); }
public ActionResult Add([Bind(Include = "Code,Description,UnitsOfMeasure,QtyOnHand")] ToolDetailVM toolVM) { if (ModelState.IsValid) { try { _toolService.Add(toolVM); return(Json(new { success = true, model = toolVM })); } catch (Exception ex) { if (ex.Message.Contains("IX_Code")) { ModelState.AddModelError("Code", "This Tool Number already exists. Duplicate Tool Numbers are not allowed."); } else { ModelState.AddModelError(string.Empty, "The save failed."); } } } return(JsonErrorResult()); }
//public JsonResult Update([Bind(Include = "Id,Code,Description,UnitsOfMeasure,QtyOnHand")]ToolVM revised) public JsonResult Update(ToolDetailVM revised) { if (ModelState.IsValid) { try { var updated = _toolService.Update(revised); return(Json(new { success = true, model = updated })); } catch (Exception ex) { if (ex.Message.Contains("IX_Code")) { ModelState.AddModelError("Code", "This Tool Number already exists. Duplicate Tool Numbers are not allowed."); } else { ModelState.AddModelError(string.Empty, "The save failed."); } } } return(JsonErrorResult()); }