Exemple #1
0
 public IActionResult Index(InspectionViewModel inspectionVM)
 {
     if (ModelState.IsValid)
     {
         using (var db = new InspectionDBContext())
         {
             db.Inspections.Add(inspectionVM.NewInspection);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }
Exemple #2
0
        public IActionResult Delete(Guid id)
        {
            InspectionViewModel inspectVm = new InspectionViewModel();

            using (InspectionDBContext db = new InspectionDBContext())
            {
                //create an instance of the view model
                inspectVm.NewInspection = new Inspection();
                //retrieve info from route data
                inspectVm.NewInspection.InspectionId =
                    Guid.Parse(RouteData.Values["id"].ToString());
                //update record status
                db.Entry(inspectVm.NewInspection).State = EntityState.Deleted;
                db.SaveChanges();
                TempData["ResultMessage"] = " The Inspection has been deleted.";
            }
            return(RedirectToAction("Index"));
        }
Exemple #3
0
 public IActionResult Edit(InspectionViewModel obj)
 {
     //check for valid view model
     if (ModelState.IsValid)
     {
         using (InspectionDBContext db = new InspectionDBContext())
         {
             //object for view model
             Inspection i = obj.NewInspection;
             //retrieve primary key/id from route data
             i.InspectionId = Guid.Parse(RouteData.Values["id"].ToString());
             //update record status
             db.Entry(i).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }