public IActionResult Edit(InspectionCodeViewModel obj)
 {
     using (InspectionCodesDBContext db = new InspectionCodesDBContext())
     {
         //check for valid model
         if (ModelState.IsValid)
         {
             //object for view model
             InspectionCode ic = obj.NewInspectionCode;
             //retrieve primary key/id from route data
             ic.InspectionCodeId = Guid.Parse(RouteData.Values["id"].ToString());
             //update record status
             db.Entry(ic).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }
        //delete an entry
        public IActionResult Delete(Guid id)
        {
            InspectionCodeViewModel iCodeVm = new InspectionCodeViewModel();

            using (InspectionCodesDBContext db = new InspectionCodesDBContext())
            {
                using (var dbI = new InspectionDBContext())
                {
                    InspectionViewModel inspectVm = new InspectionViewModel();
                    inspectVm.InspectionList = dbI.Inspections.ToList();
                    inspectVm.NewInspection  = dbI.Inspections.Where(
                        i => i.DeckInspectionCodeId == id).FirstOrDefault();

                    InspectionViewModel inspect2Vm = new InspectionViewModel();
                    inspect2Vm.InspectionList = dbI.Inspections.ToList();
                    inspect2Vm.NewInspection  = dbI.Inspections.Where(
                        i => i.SuperstructureInspectionCodeId == id).FirstOrDefault();

                    InspectionViewModel inspect3Vm = new InspectionViewModel();
                    inspect3Vm.InspectionList = dbI.Inspections.ToList();
                    inspect3Vm.NewInspection  = dbI.Inspections.Where(
                        i => i.SubstructureInspectionCodeId == id).FirstOrDefault();


                    if (inspectVm.NewInspection == null && inspect2Vm.NewInspection == null && inspect3Vm.NewInspection == null)
                    {
                        iCodeVm.NewInspectionCode = new InspectionCode();
                        //find id
                        iCodeVm.NewInspectionCode.InspectionCodeId =
                            Guid.Parse(RouteData.Values["id"].ToString());
                        //update record status
                        db.Entry(iCodeVm.NewInspectionCode).State = EntityState.Deleted;
                        db.SaveChanges();
                        TempData["ResultMessage"] = "Inspection Code deleted";
                    }
                    else
                    {
                        TempData["ResultMessage"] =
                            "This Inspection Code has dependencies, cannot delete!";
                    }
                }
            }
            return(RedirectToAction("Index"));
        }