コード例 #1
0
        public IActionResult Delete(Guid id)
        {
            MaintenanceActionViewModel mActions = new MaintenanceActionViewModel();

            using (MaintenanceActionDBContext db = new MaintenanceActionDBContext())
            {
                using (var dbMA = new MaintenanceRecordDBContext())
                {
                    MaintenanceRecordViewModel mRecordVm = new MaintenanceRecordViewModel();
                    mRecordVm.MaintenanceRecordList = dbMA.MaintenanceRecords.ToList();
                    mRecordVm.NewMaintenanceRecord  = dbMA.MaintenanceRecords.Where(
                        mr => mr.MaintenanceActionId == id).FirstOrDefault();
                    //create an instance of the view model
                    if (mRecordVm.NewMaintenanceRecord == null)
                    {
                        mActions.NewMaintenanceAction = new MaintenanceAction();
                        //retrieve info from route data
                        mActions.NewMaintenanceAction.MaintenanceActionId =
                            Guid.Parse(RouteData.Values["id"].ToString());
                        //change record status
                        db.Entry(mActions.NewMaintenanceAction).State = EntityState.Deleted;
                        db.SaveChanges();
                        TempData["ResultMessage"] = "Maintenance Action deleted";
                    }
                    else
                    {
                        TempData["ResultMessage"] = "This Maintenance Action has depentencies, unable to Delete!";
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public IActionResult Index(MaintenanceRecordViewModel maintenanceRecordVM)
        {
            using (var db = new MaintenanceRecordDBContext())
            {
                db.MaintenanceRecords.Add(maintenanceRecordVM.NewMaintenanceRecord);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
コード例 #3
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            MaintenanceRecordViewModel maintenanceRecordVM = new MaintenanceRecordViewModel();

            using (var db = new MaintenanceRecordDBContext())
            {
                maintenanceRecordVM.MaintenanceRecordList = db.MaintenanceRecords.ToList();
                maintenanceRecordVM.NewMaintenanceRecord  = new MaintenanceRecord();
            }

            return(View(maintenanceRecordVM));
        }
コード例 #4
0
        public IActionResult Delete(Guid id)
        {
            MaintenanceRecordViewModel mRecordsVm = new MaintenanceRecordViewModel();

            using (MaintenanceRecordDBContext db = new MaintenanceRecordDBContext())
            {
                //create an instance of the view model
                mRecordsVm.NewMaintenanceRecord = new MaintenanceRecord();
                //find id
                mRecordsVm.NewMaintenanceRecord.MaintenanceRecordId =
                    Guid.Parse(RouteData.Values["id"].ToString());
                //update record Status
                db.Entry(mRecordsVm.NewMaintenanceRecord).State = EntityState.Deleted;
                db.SaveChanges();
                TempData["ResultMessage"] = "The Maintenance Record was Deleted.";
            }
            return(RedirectToAction("Index"));
        }
コード例 #5
0
 public IActionResult Edit(MaintenanceRecordViewModel obj)
 {
     //check for valid view model
     if (ModelState.IsValid)
     {
         using (MaintenanceRecordDBContext db = new MaintenanceRecordDBContext())
         {
             //object for view model
             MaintenanceRecord mr = obj.NewMaintenanceRecord;
             //retrieve primary key/id from route data
             mr.MaintenanceRecordId = Guid.Parse(RouteData.Values["id"].ToString());
             //update record status
             db.Entry(mr).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }
コード例 #6
0
        //GET Filled in Form
        public IActionResult Edit(Guid id)
        {
            //a new instance of the view model
            MaintenanceRecordViewModel mRecordVM = new MaintenanceRecordViewModel();

            using (MaintenanceRecordDBContext db = new MaintenanceRecordDBContext())
            {
                //find id location in database
                mRecordVM.NewMaintenanceRecord = db.MaintenanceRecords.Where(
                    e => e.MaintenanceRecordId == id).SingleOrDefault();
                //fill in inspector drop down
                mRecordVM.Inspectors = GetInspectorsDDL();
                //fill in maintenance actions drop down
                mRecordVM.MaintenanceActions = GetMaintenanceActionsDDL();

                //return view model
                return(View(mRecordVM));
            }
        }
コード例 #7
0
        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"));
        }