コード例 #1
0
 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);
 }
コード例 #2
0
        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);
        }