public ActionResult Create(Country country) { if (ModelState.IsValid) { db.Countries.Add(country); db.SaveChanges(); return RedirectToAction("Index"); } return View(country); }
public PhilippinesData() { Country philippines = new Country(){Name ="Philippines", Provinces = new List<Province>(){ new Province(){Name="Zamboanga del Sur", Cities= new List<City>() {new City(){Name="Zamboanga City"}, new City(){Name="Pagadian"}}}, new Province(){Name="Zamboanga del Norte", Cities = new List<City>() {new City(){Name="Dipolog"},new City(){Name="Dapitan"}}}, new Province(){Name="Zamboanga Sibugay",Cities = new List<City>() {new City(){Name="Ipil"}}} } }; using (FindABookContext db = new FindABookContext()) { db.Countries.Add(philippines); db.SaveChanges(); } }
public ActionResult Edit(Country country) { if (ModelState.IsValid) { db.Entry(country).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(country); }