public ActionResult Create(CaveViewModel vm) { if (ModelState.IsValid) { vm.Initialise(db); vm.PrepareSave(); db.Caves.Add(vm.Model); db.SaveChanges(); return RedirectToAction("Index"); } vm.PopulateSelectLists(); return View(vm); }
public ActionResult Edit(CaveViewModel vm) { if (ModelState.IsValid) { var item = db.Entry(vm.Model); //var item = db.Entry<Cave>(caveVM.Model); item.State = System.Data.Entity.EntityState.Modified; vm.Initialise(db); //item.Collection(i => i.CaveAttributes).Load(); //item.Collection(i => i.CaveStatuses).Load(); //item.Collection(i => i.EaseOfAccesses).Load(); //item.Collection(i => i.Geologies).Load(); item.Collection("CaveAttributes").Load(); item.Collection("CaveStatuses").Load(); item.Collection("EaseOfAccesses").Load(); item.Collection("Geologies").Load(); vm.PrepareSave(); //item.Collection(i => i.CaveStatuses).Load(); //caveVM.Model.CaveStatuses.Clear(); //foreach (var scs in caveVM.SelectedCaveStatuses) //{ // //var status = LookupRepository.CaveStatusList.Single(p=> p.CaveStatusID == scs); // var asd = db.CaveStatuses.Find(scs); // caveVM.Model.CaveStatuses.Add(asd); //} db.SaveChanges(); return RedirectToAction("Index"); } //caveVM.ExplorationStatusSelectList = new SelectList(LookupRepository.ExplorationStatusList, "ExplorationStatusID", "Description", caveVM.Model.ExplorationStatusID); //caveVM.LocationStatusSelectList = new SelectList(LookupRepository.LocationStatusList, "LocationStatusID", "Description", caveVM.Model.LocationStatusID); //caveVM.ProvincesSelectList = new SelectList(LookupRepository.ProvinceList, "ProvinceID", "Description", caveVM.Model.ProvinceID); //caveVM.CaveStatusSelectList = new SelectList(LookupRepository.CaveStatusList, "CaveStatusID", "Description"); //caveVM.CaveAttributeSelectList = new SelectList(LookupRepository.CaveAttributeList, "CaveAttributeID", "Description"); //caveVM.Model.PopulateRelatedEntitesFromIDs(); vm.PopulateSelectLists(); return View(vm); }