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");
        }
示例#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 });
        }
示例#3
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 });
        }
示例#4
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 });
        }
        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");
        }
示例#6
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 });
        }
示例#7
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());
        }