//GET Filled in Form public IActionResult Edit(Guid id) { //a new instance of the view model MaterialDesignViewModel mDesign = new MaterialDesignViewModel(); using (MaterialDesignDBContext db = new MaterialDesignDBContext()) { //find id location in database mDesign.NewMaterialDesign = db.MaterialDesigns.Where( e => e.MaterialDesignId == id).SingleOrDefault(); //return view model return(View(mDesign)); } }
public IActionResult Edit(MaterialDesignViewModel obj) { //check for valid model if (ModelState.IsValid) { using (MaterialDesignDBContext db = new MaterialDesignDBContext()) { //object for view model MaterialDesign md = obj.NewMaterialDesign; //retrieve primary key/id from route data md.MaterialDesignId = Guid.Parse(RouteData.Values["id"].ToString()); //update record status db.Entry(md).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); }
private static List <SelectListItem> GetMaterialDesignsDDL() { List <SelectListItem> material = new List <SelectListItem>(); MaterialDesignViewModel mdvm = new MaterialDesignViewModel(); using (var db = new MaterialDesignDBContext()) { mdvm.MaterialDesignList = db.MaterialDesigns.ToList(); } foreach (MaterialDesign m in mdvm.MaterialDesignList) { material.Add(new SelectListItem { Text = m.MaterialDesignType, Value = m.MaterialDesignId.ToString() }); } return(material); }