public ActionResult Create(Tournament tournament) { tournament.SeasonId = CurrentSeason.Id; if (tournament.LeagueId == 0) { tournament.LeagueId = null; tournament.LeagueName = null; tournament.Type = "Random"; } if (tournament.Type == "League") { var league = Unit.LeagueRepository.GetById(tournament.LeagueId); tournament.LeagueName = league.Name; } if (ModelState.IsValid) { Unit.TournamentRepository.Insert(tournament); Unit.Save(); if (tournament.Type == "League") { return RedirectToAction("IndexTournament", "Game", new { LeagueId = tournament.LeagueId }); } else { return RedirectToAction("Index"); } } ViewBag.LeagueId = new SelectList(Unit.LeagueRepository.Get(filter: l => l.Type == "Tournament"), "Id", "Name", tournament.LeagueId); return View(tournament); }
public ActionResult Edit(Tournament tournament) { if (tournament.LeagueId == 0) { tournament.LeagueId = null; tournament.LeagueName = null; tournament.Type = "Random"; } if (tournament.Type == "League") { var league = Unit.LeagueRepository.GetById(tournament.LeagueId); tournament.LeagueName = league.Name; } else { tournament.LeagueName = ""; tournament.LeagueId = null; } if (ModelState.IsValid) { Unit.TournamentRepository.Update(tournament); Unit.Save(); if (tournament.Type == "League") { return RedirectToAction("IndexTournament", "Game", new { LeagueId = tournament.LeagueId }); } else { return RedirectToAction("Index"); } } ViewBag.LeagueId = new SelectList(Unit.LeagueRepository.Get(filter: l => l.Type == "Tournament"), "Id", "Name", tournament.LeagueId); ViewBag.StartTime = tournament.StartTime; ViewBag.StartDate = tournament.StartDate.ToShortDateString(); ViewBag.EndDate = tournament.EndDate.ToShortDateString(); return View(tournament); }