コード例 #1
0
        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"));
        }
コード例 #2
0
 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"));
 }