public void InsertOrUpdate(Match match) { if (match.Id == default(int)) { // New entity context.Matches.Add(match); } else { // Existing entity context.Matches.Attach(match); context.Entry(match).State = EntityState.Modified; } }
public ActionResult Create(Match match) { match.WinnerRank = (short)this.ladderRepository.GetPlayerStanding(match.LadderWeekId, match.WinnerId); match.LooserRank = (short)this.ladderRepository.GetPlayerStanding(match.LadderWeekId, match.LooserId); if (ModelState.IsValid) { matchRepository.InsertOrUpdate(match); matchRepository.Save(); // UpdateStandings(match.LadderWeekId, match.LadderWeekId); return RedirectToAction("Index"); } else { ViewBag.PossibleWinners = playerRepository.GetAllPlayers(); ViewBag.PossibleLoosers = playerRepository.GetAllPlayers(); ViewBag.PossibleLadderWeeks = ladderRepository.LadderWeeks(); return View(); } }
public ActionResult Edit(Match match) { if (ModelState.IsValid) { matchRepository.InsertOrUpdate(match); matchRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleWinners = playerRepository.GetAllPlayers(); ViewBag.PossibleLoosers = playerRepository.GetAllPlayers(); return View(); } }