コード例 #1
0
ファイル: MatchController.cs プロジェクト: riyaniss/WC
        public ActionResult Change(MatchesTeam mt, FormCollection form)
        {
            MatchesTeam teamLocal = new MatchesTeam() { matchId = int.Parse(form["matchId"].ToString()), teamId = int.Parse(form["dropHome"].ToString()), teamIsLocal = true };
            MatchesTeam teamAway = new MatchesTeam() { matchId = int.Parse(form["matchId"].ToString()), teamId = int.Parse(form["dropAway"].ToString()), teamIsLocal = false };

            Context ctx = new Context();

            int matchId = int.Parse(form["matchId"].ToString());

            var exists = (from ma in ctx.MatchesTeam
                          where ma.matchId == matchId
                          select ma).ToList();

            if (exists.Count == 0)
            {
                ctx.MatchesTeam.Add(teamLocal);
                ctx.MatchesTeam.Add(teamAway);
            }
            else
            {
                if (exists[0].teamIsLocal == true)
                {
                    exists[0].teamId = int.Parse(form["dropHome"].ToString());
                    exists[1].teamId = int.Parse(form["dropAway"].ToString());
                }
                else
                {
                    exists[1].teamId = int.Parse(form["dropHome"].ToString());
                    exists[0].teamId = int.Parse(form["dropAway"].ToString());
                }

            }
            ctx.SaveChanges();
            return RedirectToAction("List", "Match");
        }
コード例 #2
0
ファイル: MatchController.cs プロジェクト: riyaniss/WC
        public ActionResult Change(int id)
        {
            Context ctx = new Context();

            var matchTeams = (from mt in ctx.MatchesTeam
                              where mt.matchId == id
                              select mt).FirstOrDefault();

            var teams = (from t in ctx.Teams
                         select t).ToList();

            var results = new List<SelectListItem>();

            foreach (Teams t in teams)
            {
                results.Add(new SelectListItem() { Text = t.teamName, Value = t.teamId.ToString() });
            }

            ViewBag.HomeTeam = results;
            ViewBag.AwayTeam = results;

            if (matchTeams == null)
            {
                matchTeams = new MatchesTeam();
                matchTeams.matchId = id;
                matchTeams.teamId = 0;
                matchTeams.teamIsLocal = true;
            }

            return View(matchTeams);
        }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: riyaniss/WC
        public ActionResult ApplyFormulaMatch(int id)
        {
            Context ctx = new Context();

            var match = (from m in ctx.Matches
                         where m.matchId == id
                         select m).FirstOrDefault();
            string formula = string.Empty;
            if (match.IsFormula)
            {
                if (match.formulaByGroups)
                {
                    formula = match.formula;
                    string[] groups = formula.Split(new char[] { '-' });

                    var firstLeg = (from g in ctx.Groups
                               from t in ctx.Teams
                               where g.groupName.Contains(" " + groups[0].Substring(0, 1))
                               && t.groupId == g.groupId
                               select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList();

                    var secondLeg = (from g in ctx.Groups
                                     from t in ctx.Teams
                                     where g.groupName.Contains(" " + groups[1].Substring(0, 1))
                                     && t.groupId == g.groupId
                                     select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList();

                    Teams teamId1 = null;
                    Teams teamId2 = null;

                    if (groups[0].Substring(1, 1).ToString().Equals("1"))
                        teamId1 = firstLeg.FirstOrDefault();
                    else
                        teamId1 = firstLeg.Skip(1).Take(1).SingleOrDefault();

                    if(groups[1].Substring(1, 1).ToString().Equals("1"))
                         teamId2 = secondLeg.FirstOrDefault();
                    else
                        teamId2 = secondLeg.Skip(1).Take(1).SingleOrDefault();

                    MatchesTeam mt = new MatchesTeam();
                    mt.matchId = match.matchId;
                    mt.teamId = teamId1.teamId;
                    mt.teamIsLocal = true;
                    ctx.MatchesTeam.Add(mt);

                    mt = new MatchesTeam();
                    mt.matchId = match.matchId;
                    mt.teamId = teamId2.teamId;
                    mt.teamIsLocal = false;
                    ctx.MatchesTeam.Add(mt);

                }
                else
                {
                    formula = match.formula;
                    string[] games = formula.Split(new char[] { '-' });

                    int matchFormula = 0;

                    if (games[0].Substring(0, 1).ToString().Equals("W"))
                    {
                        matchFormula = int.Parse(games[0].Substring(1, 2).ToString());

                        var matchResult = (from m in ctx.Matches
                                           where m.matchId == matchFormula
                                           select m).FirstOrDefault();

                    }
                    else
                    { }
                }

                ctx.SaveChanges();

                return View();
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
        }