public ActionResult Create(TournamentMVCCreateModel model) { try { if (ModelState.IsValid && model.SelectedEnteredTeams.Count > 0) { List <PrizeModel> allPrizes = GlobalConfig.Connection.GetPrizes_All(); List <TeamModel> allTeams = GlobalConfig.Connection.GetTeam_All(); TournamentModel t = new TournamentModel(); t.TournamentName = model.TournamentName; t.EntryFee = model.EntryFee; t.EnteredTeams = model.SelectedEnteredTeams.Select(x => allTeams.Where(y => y.Id == int.Parse(x)).First()).ToList(); t.Prizes = model.SelectedPrizes.Select(x => allPrizes.Where(y => y.Id == int.Parse(x)).First()).ToList(); //Wire our matchups TournamentLogic.CreateRounds(t); GlobalConfig.Connection.CreateTournament(t); t.AlertUsersToNewRound(); return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Create")); } } catch (Exception ex) { return(View()); } }
// GET: Tournaments/Create public ActionResult Create() { TournamentMVCCreateModel input = new TournamentMVCCreateModel(); List <TeamModel> allTeams = GlobalConfig.Connection.GetTeam_All(); List <PrizeModel> allPrizes = GlobalConfig.Connection.GetPrizes_All(); input.EnteredTeams = allTeams.Select(x => new SelectListItem { Text = x.TeamName, Value = x.Id.ToString() }).ToList(); input.Prizes = allPrizes.Select(x => new SelectListItem { Text = x.PlaceName, Value = x.Id.ToString() }).ToList(); return(View(input)); }