Exemplo n.º 1
0
        // GET: /Home/
        public ActionResult Index()
        {
            IEnumerable<Tournament.Data.Tournament> tournaments = null;

            using (TournamentEntities data = new TournamentEntities())
            {
                tournaments = data.Tournaments.ToList();
            }

            return View(tournaments);
        }
Exemplo n.º 2
0
        public ActionResult Add(Group group)
        {
            if (!String.IsNullOrEmpty(group.Name) && group.TournamentID > 0)
            {
                using (TournamentEntities data = new TournamentEntities())
                {
                    data.Groups.AddObject(group);
                    data.SaveChanges();
                }
            }

            return RedirectToAction("Index", "Tournament", new { id = group.TournamentID });
        }
Exemplo n.º 3
0
        public ActionResult Add(Tournament.Data.Tournament tournament)
        {
            if (!String.IsNullOrEmpty(tournament.Name))
            {
                using (TournamentEntities data = new TournamentEntities())
                {
                    data.Tournaments.AddObject(tournament);
                    data.SaveChanges();
                }
            }

            return RedirectToAction("Index", "Home");
        }
Exemplo n.º 4
0
        public ActionResult Add(Team team)
        {
            using (TournamentEntities data = new TournamentEntities())
            {
                Group group = data.Groups.SingleOrDefault(g => g.GroupID == team.GroupID);

                if (group != null)
                {
                    data.Teams.AddObject(team);
                    data.SaveChanges();
                }
            }

            return RedirectToAction("Index", "Group", new { id = team.GroupID });
        }
Exemplo n.º 5
0
        public ActionResult Delete(int id)
        {
            Tournament.Data.Tournament tournament = null;

            using (TournamentEntities data = new TournamentEntities())
            {
                tournament = data.Tournaments.SingleOrDefault(t => t.TournamentID == id);
            }

            if (tournament != null)
            {
                return View("Delete", tournament);
            }

            return View("Error");
        }
Exemplo n.º 6
0
        public ActionResult Edit(int id, Team postedTeam)
        {
            using (TournamentEntities data = new TournamentEntities())
            {
                Team team = data.Teams.SingleOrDefault(t => t.TeamID == id);

                if (team != null)
                {
                    UpdateModel<Team>(team);

                    data.SaveChanges();
                }
            }

            return RedirectToAction("Index", new { id = id });
        }
Exemplo n.º 7
0
        // GET: /Fixture/5
        public ActionResult Index(int id)
        {
            FixtureList fixtures = null;

            using (TournamentEntities data = new TournamentEntities())
            {
                Group group = data.Groups.SingleOrDefault(g => g.GroupID == id);

                if (group != null)
                {
                    fixtures = new FixtureList(group);
                }
            }

            ViewBag.GroupID = id;

            return View("Index", fixtures);
        }
Exemplo n.º 8
0
        public ActionResult Delete(int tournamentID, string submit)
        {
            if (tournamentID > 0 && submit == "Delete")
            {
                using (TournamentEntities data = new TournamentEntities())
                {
                    var tournament = data.Tournaments.SingleOrDefault(t => t.TournamentID == tournamentID);

                    if (tournament != null)
                    {
                        data.Tournaments.DeleteObject(tournament);
                        data.SaveChanges();
                    }
                }
            }

            return RedirectToAction("Index");
        }
Exemplo n.º 9
0
        public ActionResult Generate(int id, int numberOfRounds, string submit)
        {
            if (submit == "Generate Fixtures")
            {
                if ((numberOfRounds % 2) != 0)
                {
                    return RedirectToAction("Generate", new { id = id });
                }

                using (TournamentEntities data = new TournamentEntities())
                {
                    Group group = data.Groups.SingleOrDefault(g => g.GroupID == id);

                    if (group != null)
                    {
                        // We add rounds 2 at a time, home and away
                        for (int round = 2; round <= numberOfRounds; round += 2)
                        {
                            foreach (Team team in group.Teams)
                            {
                                foreach (Team opponent in group.Teams)
                                {
                                    if (opponent.TeamID != team.TeamID)
                                    {
                                        Fixture fixture = new Fixture()
                                        {
                                            HomeTeamID = team.TeamID,
                                            AwayTeamID = opponent.TeamID,
                                        };

                                        data.Fixtures.AddObject(fixture);
                                    }
                                }
                            }
                        }

                        data.SaveChanges();
                    }
                }
            }

            return RedirectToAction("Index", new { id = id });
        }
Exemplo n.º 10
0
        // GET: /Group/
        public ActionResult Index(int id)
        {
            GroupTable model = null ;

            using (TournamentEntities data = new TournamentEntities())
            {
                Group group = data.Groups.SingleOrDefault(g => g.GroupID == id);

                if (group != null)
                {
                    model = new GroupTable(group);
                }
            }

            if (model != null)
            {
                return View("Index", model);
            }

            return View("Error");
        }
Exemplo n.º 11
0
        // GET: /Tournament/5
        public ActionResult Index(int id)
        {
            TournamentSummary model = null;

            using (TournamentEntities data = new TournamentEntities())
            {
                Tournament.Data.Tournament tournament = data.Tournaments.SingleOrDefault(t => t.TournamentID == id);

                if (tournament != null)
                {
                    model = new TournamentSummary(tournament);
                }
            }

            if (model != null)
            {
                return View("Index", model);
            }

            return View("Error");
        }
Exemplo n.º 12
0
        // GET: /Team/5
        public ActionResult Index(int id)
        {
            TeamDetails teamDetails = null;

            using (TournamentEntities data = new TournamentEntities())
            {
                Team team = data.Teams.SingleOrDefault(t => t.TeamID == id);

                if (team != null)
                {
                    teamDetails = new TeamDetails(team);
                }
            }

            if (teamDetails != null)
            {
                return View("Index", teamDetails);
            }

            return View("Error");
        }
Exemplo n.º 13
0
        public ActionResult Update(int fixtureID, int homeScore, int awayScore)
        {
            int groupID = 0;

            using (TournamentEntities data = new TournamentEntities())
            {
                Fixture updatedFixture = data.Fixtures.SingleOrDefault(f => f.FixtureID == fixtureID);

                if (updatedFixture != null && updatedFixture.Result == null)
                {
                    groupID = updatedFixture.HomeTeam.GroupID;

                    updatedFixture.Result = new Result()
                    {
                        AwayScore = awayScore,
                        HomeScore = homeScore
                    };

                    data.SaveChanges();
                }
            }

            return Redirect(Request.UrlReferrer.ToString());
        }