public ActionResult SaveNewOrExisting(int? id, Monster monster) { if (!this.ModelState.IsValid) return MonsterView(monster); using (var db = MonstersRepository.Get()) { // 'Add' works here even if it already exists in the collection--SaveChanges fixes things up. // (It's not a real application anyway:) Use the correct data access type shenanigans for your app. db.Monsters.Add(monster); db.SaveChanges(); } return this.RedirectTo(SiteUrls.MonsterDetail[monster.Id]); }
public ViewResult MonsterView(Monster monster) { this.ViewBag.AllCategories = MonstersRepository.Get().Categories; return View("Detail", monster); }