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")); }
//GET Filled in Form public IActionResult Edit(Guid id) { //a new instance of the view model InspectionViewModel inspectVM = new InspectionViewModel(); using (InspectionDBContext db = new InspectionDBContext()) { //find id location in database inspectVM.NewInspection = db.Inspections.Where( e => e.InspectionId == id).SingleOrDefault(); //fill in bridgeid drop down inspectVM.Bridges = GetBridgesDDL(); //fill in inspectors drop down inspectVM.Inspectors = GetInspectorsDDL(); //fill in deck inspection drop down inspectVM.DeckInspections = GetInspectionsDDL(); //fill in superstructure drop down inspectVM.SuperInspections = GetInspectionsDDL(); //fill in substructure drop down inspectVM.SubInspections = GetInspectionsDDL(); //return view model return(View(inspectVM)); } }
public IActionResult Index(InspectionViewModel inspectionVM) { if (ModelState.IsValid) { using (var db = new InspectionDBContext()) { db.Inspections.Add(inspectionVM.NewInspection); db.SaveChanges(); } } return(RedirectToAction("Index")); }
// GET: /<controller>/ public IActionResult Index() { InspectionViewModel inspectionVM = new InspectionViewModel(); using (var db = new InspectionDBContext()) { inspectionVM.InspectionList = db.Inspections.ToList(); inspectionVM.NewInspection = new Inspection(); } return(View(inspectionVM)); }
// GET: /<controller>/ public IActionResult Index() { InspectionViewModel inspectionVM = new InspectionViewModel(); using (var db = new InspectionDBContext()) { inspectionVM.InspectionList = db.Inspections.ToList(); inspectionVM.NewInspection = new Inspection(); inspectionVM.Bridges = GetBridgesDDL(); inspectionVM.Inspectors = GetInspectorsDDL(); inspectionVM.DeckInspections = GetInspectionsDDL(); inspectionVM.SuperInspections = GetInspectionsDDL(); inspectionVM.SubInspections = GetInspectionsDDL(); } return(View(inspectionVM)); }
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")); }
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")); }
private static List <SelectListItem> GetInspectionsDDDL() { List <SelectListItem> deck = new List <SelectListItem>(); InspectionViewModel isvm = new InspectionViewModel(); using (var db = new InspectionDBContext()) { isvm.InspectionList = db.Inspections.ToList(); } foreach (Inspection ip in isvm.InspectionList) { deck.Add(new SelectListItem { Text = ip.DeckInspectionCodeId.ToString() }); } return(deck); }
private static List <SelectListItem> GetInspectionsSubDDL() { List <SelectListItem> substruct = new List <SelectListItem>(); InspectionViewModel isvm3 = new InspectionViewModel(); using (var db = new InspectionDBContext()) { isvm3.InspectionList = db.Inspections.ToList(); } foreach (Inspection ip3 in isvm3.InspectionList) { substruct.Add(new SelectListItem { Text = ip3.SubstructureInspectionCodeId.ToString() }); } return(substruct); }
//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")); }
public IActionResult Delete(Guid id) { InspectorViewModel inspectorVm = new InspectorViewModel(); using (InspectorDBContext db = new InspectorDBContext()) { using (var dbI = new InspectionDBContext()) using (var dbMR = new MaintenanceRecordDBContext()) { InspectionViewModel inspectionVm = new InspectionViewModel(); inspectionVm.InspectionList = dbI.Inspections.ToList(); inspectionVm.NewInspection = dbI.Inspections.Where( i => i.InspectorId == id).FirstOrDefault(); MaintenanceRecordViewModel MRecordVm = new MaintenanceRecordViewModel(); MRecordVm.MaintenanceRecordList = dbMR.MaintenanceRecords.ToList(); MRecordVm.NewMaintenanceRecord = dbMR.MaintenanceRecords.Where( i => i.InspectorId == id).FirstOrDefault(); //create an instance of the view model if (inspectionVm.NewInspection == null && MRecordVm.NewMaintenanceRecord == null) { inspectorVm.NewInspector = new Inspector(); //find id inspectorVm.NewInspector.InspectorId = Guid.Parse(RouteData.Values["id"].ToString()); //update record status db.Entry(inspectorVm.NewInspector).State = EntityState.Deleted; db.SaveChanges(); TempData["ResultMessage"] = "Inspector Deletion Successful"; } else { TempData["ResultMessage"] = "Dependencies Found. This Inspector cannot be deleted!"; } } } return(RedirectToAction("Index")); }