public IActionResult Delete(Guid id)
        {
            BridgeViewModel bridgeVm = new BridgeViewModel();

            using (BridgeDBContext db = new BridgeDBContext())
            {
                using (var dbI = new InspectionDBContext())
                {
                    InspectionViewModel inspectVm = new InspectionViewModel();
                    inspectVm.InspectionList = dbI.Inspections.ToList();
                    inspectVm.NewInspection  = dbI.Inspections.Where(
                        i => i.BridgeId == id).FirstOrDefault();
                    //create an instance of the view model
                    if (inspectVm.NewInspection == null)
                    {
                        bridgeVm.NewBridge = new Bridge();
                        //retrieve info from route data
                        bridgeVm.NewBridge.Bridgeid =
                            Guid.Parse(RouteData.Values["id"].ToString());
                        //update recode state
                        db.Entry(bridgeVm.NewBridge).State = EntityState.Deleted;
                        db.SaveChanges();
                        TempData["ResultMessage"] = "Bridge Record Deleted";
                    }
                    else
                    {
                        TempData["ResultMessage"] = "This Bridge Record has Dependencies.  This Record cannot be Deleted!";
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
        public IActionResult Index(BridgeViewModel bridgeVM)
        {
            using (var db = new BridgeDBContext())
            {
                db.Bridges.Add(bridgeVM.NewBridge);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
 public IActionResult Index(BridgeViewModel bridgeAdd)
 {
     if (ModelState.IsValid)
     {
         using (var db = new BridgeDBContext())
         {
             db.Bridges.Add(bridgeAdd.NewBridge);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }
 public IActionResult Edit(BridgeViewModel obj)
 {
     //check for valid model state
     if (ModelState.IsValid)
     {
         using (BridgeDBContext db = new BridgeDBContext())
         {
             //instance of object
             Bridge b = obj.NewBridge;
             //retrieve info from route data
             b.Bridgeid = Guid.Parse(RouteData.Values["id"].ToString());
             //update record state
             db.Entry(b).State = EntityState.Modified;
             //save changes
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }