public ActionResult Create(ObservableEntityViewModel vm) { if (ModelState.IsValid) { vm.Initialise(db); vm.PrepareSave(); db.ObservableEntities.Add(vm.Model); db.SaveChanges(); return RedirectToAction("Index"); } vm.PopulateSelectLists(); return View(vm); }
public ActionResult Edit(ObservableEntityViewModel vm) { if (ModelState.IsValid) { var item = db.Entry(vm.Model); item.State = EntityState.Modified; vm.Initialise(db); item.Collection("ObservableEntityTypes").Load(); vm.PrepareSave(); //var existingObservableEntity = db.ObservableEntities.Find(observableEntity.ObservableEntityID); //existingObservableEntity.Name = observableEntity.Name; //existingObservableEntity.ScientificName = observableEntity.ScientificName; db.SaveChanges(); return RedirectToAction("Index"); } vm.PopulateSelectLists(); return View(vm); }