Beispiel #1
0
        public IActionResult Delete(Guid id)
        {
            FunctionalClassViewModel fClassVm = new FunctionalClassViewModel();

            using (FunctionalClassDBContext db = new FunctionalClassDBContext())
            {
                using (var dbB = new BridgeDBContext())
                {
                    BridgeViewModel bridgeVm = new BridgeViewModel();
                    bridgeVm.BridgeList = dbB.Bridges.ToList();
                    bridgeVm.NewBridge  = dbB.Bridges.Where(
                        fc => fc.FunctionalClassId == id).FirstOrDefault();
                    if (bridgeVm.NewBridge == null)
                    {
                        fClassVm.NewFunctionalClass = new FunctionalClass();
                        //retrieve info from route data
                        fClassVm.NewFunctionalClass.FunctionalClassId =
                            Guid.Parse(RouteData.Values["id"].ToString());
                        //update record status
                        db.Entry(fClassVm.NewFunctionalClass).State = EntityState.Deleted;
                        db.SaveChanges();
                        TempData["ResultMessage"] = "Functional Class deleted";
                    }
                    else
                    {
                        TempData["ResultMessage"] =
                            "This Functional Class has dependencies, cannot delete!";
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public IActionResult Edit(FunctionalClassViewModel obj)
 {
     //check for valid model
     if (ModelState.IsValid)
     {
         using (FunctionalClassDBContext db = new FunctionalClassDBContext())
         {
             //object for view model
             FunctionalClass fc = obj.NewFunctionalClass;
             //retrieve primary key/id from route data
             fc.FunctionalClassId = Guid.Parse(RouteData.Values["id"].ToString());
             //update record status
             db.Entry(fc).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }