public ActionResult Create(Playground playground) { if (ModelState.IsValid) { if (playground.SportTypeId == 0) { playground.SportTypeId = 1; } playgroundRepository.InsertOrUpdate(playground); playgroundRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleSportComplexes = sportcomplexRepository.All; ViewBag.PossibleSurfaces = surfaceRepository.All; return View(); } }
public void InsertOrUpdate(Playground playground) { if (playground.PlaygroundId == default(int)) { // New entity context.Playgrounds.Add(playground); } else { // Existing entity context.Entry(playground).State = EntityState.Modified; } }