コード例 #1
0
        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());
            }
        }
コード例 #2
0
        //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));
        }
コード例 #3
0
 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());
 }
コード例 #4
0
        //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());
        }