public ActionResult Create(Special special) { ViewData["HousesList"] = House.BuildHousesDropdownList(); if (ModelState.IsValid) { special.House = db.Houses.Include("Location").Include("Owner").Include("Owner.Location").Include("ManagementCompany").Include("ManagementCompany.Location").Single(m => m.ID == special.House.ID); List<Cost> costs = new List<Cost>(); foreach (Cost c in special.Costs) { if (c.Name != null) costs.Add(c); } special.Costs = costs; db.Specials.Add(special); Success("A special for " + special.House.Name + " was added successfully!"); db.SaveChanges(); return RedirectToAction("Index"); } Error("Something went wrong! The special was not added."); return View(special); }
public ActionResult Edit(Special special) { if (ModelState.IsValid) { Special s = db.Specials.Include("House").Include("House.Location").Include("House.Owner").Include("House.Owner.Location").Include("House.ManagementCompany").Include("House.ManagementCompany.Location").Single(m => m.ID == special.ID); db.Entry(s).CurrentValues.SetValues(special); foreach (Cost c in special.Costs) db.Entry(c).State = EntityState.Modified; db.SaveChanges(); Success("Changes were successfully saved!"); return RedirectToAction("Index"); } Error("Something went wrong! Changes were not saved."); return View(special); }