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"));
        }
 public IActionResult Index(MaintenanceActionViewModel maintenanceActionAdd)
 {
     if (ModelState.IsValid)
     {
         using (var db = new MaintenanceActionDBContext())
         {
             db.MaintenanceActions.Add(maintenanceActionAdd.NewMaintenanceAction);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }
        // GET: /<controller>/
        public IActionResult Index()
        {
            MaintenanceActionViewModel maintenanceActionVM = new MaintenanceActionViewModel();

            using (var db = new MaintenanceActionDBContext())
            {
                maintenanceActionVM.MaintenanceActionList = db.MaintenanceActions.ToList();
                maintenanceActionVM.NewMaintenanceAction  = new MaintenanceAction();
            }

            return(View(maintenanceActionVM));
        }
        //GET Filled in Form
        public IActionResult Edit(Guid id)
        {
            //a new instance of the view model
            MaintenanceActionViewModel mActionVM = new MaintenanceActionViewModel();

            using (MaintenanceActionDBContext db = new MaintenanceActionDBContext())
            {
                //find id location in databased
                mActionVM.NewMaintenanceAction = db.MaintenanceActions.Where(
                    e => e.MaintenanceActionId == id).SingleOrDefault();

                //return view model
                return(View(mActionVM));
            }
        }
 public IActionResult Edit(MaintenanceActionViewModel obj)
 {
     //check for valid view model
     if (ModelState.IsValid)
     {
         using (MaintenanceActionDBContext db = new MaintenanceActionDBContext())
         {
             //object for view model
             MaintenanceAction ma = obj.NewMaintenanceAction;
             //retrieve primary key/id from route data
             ma.MaintenanceActionId = Guid.Parse(RouteData.Values["id"].ToString());
             //update record status
             db.Entry(ma).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }
        private static List <SelectListItem> GetMaintenanceActionsDDL()
        {
            List <SelectListItem>      action = new List <SelectListItem>();
            MaintenanceActionViewModel mavm   = new MaintenanceActionViewModel();

            using (var db = new MaintenanceActionDBContext())
            {
                mavm.MaintenanceActionList = db.MaintenanceActions.ToList();
            }
            foreach (MaintenanceAction ma in mavm.MaintenanceActionList)
            {
                action.Add(new SelectListItem
                {
                    Text  = ma.MaintenanceActionName,
                    Value = ma.MaintenanceActionId.ToString()
                });
            }
            return(action);
        }