public ActionResult Create(TournamentCreateMvcModel model) { try { if (ModelState.IsValid && model.SelectedTeamsEntered.Count > 0) { List <TeamModel> availableTeams = GlobalConfiguration.Connection.Teams_GetAll(); TournamentModel t = new TournamentModel { TournamentStartDate = model.TournamentDateStart.Add(model.TournamentTimeStart), TournamentEndDate = model.TournamentDateEnd.Add(model.TournamentTimeEnd) }; if (t.TournamentEndDate <= t.TournamentStartDate) { return(RedirectToAction("Create")); } t.TournamentName = model.TournamentName; t.TeamsEntered = model.SelectedTeamsEntered.Select(x => availableTeams.First(y => y.Id == int.Parse(x))).ToList(); t.Format = Int32.Parse(model.SelectedFormat); int numberOfDivisions = Int32.Parse(model.SelectedDivisions); for (int i = 1; i <= numberOfDivisions; i++) { DivisionModel d = new DivisionModel { DivisionName = "Division " + i }; for (int j = 0; j < 2; j++) { GroupModel y = new GroupModel(); d.Groups.Add(y); } t.DivisionsEntered.Add(d); } GlobalConfiguration.Connection.CreateTournament(t); return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Create")); } } catch { return(View()); } }
// GET: Tournament/Create public ActionResult Create() { TournamentCreateMvcModel input = new TournamentCreateMvcModel(); List <TeamModel> availableTeams = GlobalConfiguration.Connection.Teams_GetAll(); input.TeamsEntered = availableTeams.Select(x => new SelectListItem { Text = x.TeamName, Value = x.Id.ToString() }).ToList(); return(View(input)); }