コード例 #1
0
        public TournamentStructure GetTournament(int id)
        {
            using (var context = new LoLEsportsDbContext())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        TournamentStructure tourney = new TournamentStructure();
                        Tournament          t       = context.Tournament.Where(i => i.TournamentId == id).FirstOrDefault();
                        if (t == null)
                        {
                            tourney.error   = 1;
                            tourney.message = "Tournament does not exist in the database.";
                            return(tourney);
                        }
                        tourney.TournamentName = t.TournamentName;
                        tourney.StartDate      = t.StartDate;
                        tourney.EndDate        = t.EndDate;
                        tourney.Season         = t.Season;
                        PlayerTransaction p = new PlayerTransaction();
                        tourney.MVP = p.GetPlayer(t.Mvpid);
                        Coach c = context.Coach.Where(i => i.CoachId == t.Mvcid).FirstOrDefault();
                        tourney.MVCName = context.Person.Where(i => i.PersonId == c.PersonId).Select(x => x.PersonName).FirstOrDefault();
                        tourney.MVCIgn  = c.CoachIgn;
                        MatchTransaction mt = new MatchTransaction();
                        TeamTransaction  tt = new TeamTransaction();
                        tourney.TournamentBanner = t.TournamentBanner;
                        tourney.Matches          = new List <SimpleMatchStructure>();
                        tourney.Standings        = new List <StandingsStructure>();
                        context.Team.ToList().ForEach((team) =>
                        {
                            StandingsStructure s = new StandingsStructure();
                            s.TeamName           = team.TeamName;
                            s.TeamLogo           = team.TeamPicture;
                            s.TeamId             = team.TeamId;
                            tourney.Standings.Add(s);
                        });
                        context.Match.Where(i => (!i.IsFinals).GetValueOrDefault() && (!i.IsQuarters).GetValueOrDefault() && (!i.IsSemis).GetValueOrDefault() && i.TournamentId == t.TournamentId).OrderBy(o => o.DatePlayed)
                        .ToList().ForEach((match) =>
                        {
                            SimpleMatchStructure sms = new SimpleMatchStructure();
                            sms.MatchId     = match.MatchId;
                            sms.DatePlayed  = match.DatePlayed;
                            sms.WinningTeam = tt.GetTeam(match.WinningTeamId);
                            sms.LosingTeam  = tt.GetTeam(match.LosingTeamId);
                            tourney.Matches.Add(sms);
                            tourney.Standings.Find(l => l.TeamName == sms.WinningTeam.TeamName).Wins++;
                            tourney.Standings.Find(l => l.TeamName == sms.LosingTeam.TeamName).Losses++;
                        });
                        tourney.Playsoffs = new List <SimpleMatchStructure>();
                        context.Match.Where(i => ((i.IsFinals).GetValueOrDefault() == true || (i.IsQuarters).GetValueOrDefault() == true || (i.IsSemis).GetValueOrDefault() == true) && i.TournamentId == t.TournamentId).OrderBy(o => o.DatePlayed)
                        .ToList().ForEach((match) =>
                        {
                            SimpleMatchStructure sms = new SimpleMatchStructure();
                            sms.MatchId     = match.MatchId;
                            sms.DatePlayed  = match.DatePlayed;
                            sms.WinningTeam = tt.GetTeam(match.WinningTeamId);
                            sms.LosingTeam  = tt.GetTeam(match.LosingTeamId);
                            tourney.Playsoffs.Add(sms);
                        });
                        tourney.Standings = tourney.Standings.OrderByDescending(o => o.Wins).ThenBy(x => x.Losses).ToList();


                        dbContextTransaction.Commit();
                        return(tourney);
                    }
                    catch (Exception e)
                    {
                        TournamentStructure tourney = new TournamentStructure();
                        tourney.error   = 1;
                        tourney.message = e.ToString();
                        dbContextTransaction.Rollback();
                        return(tourney);
                    }
                }
            }
        }
コード例 #2
0
        public MatchStructure GetMatch(int id)
        {
            using (var context = new LoLEsportsDbContext())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        MatchStructure match = new MatchStructure();
                        Match          m     = context.Match.Where(i => i.MatchId == id).FirstOrDefault();
                        if (m == null)
                        {
                            match.error   = 1;
                            match.message = "Match does not exist in the database.";
                            return(match);
                        }

                        match.DatePlayed    = m.DatePlayed;
                        match.MatchLocation = m.MatchLocation;
                        match.Duration      = m.Duration;

                        Team            wt = context.Team.Where(i => i.TeamId == m.WinningTeamId).FirstOrDefault();
                        TeamTransaction tt = new TeamTransaction();
                        match.WinningTeam = tt.GetTeam(wt.TeamId);
                        Team lt = context.Team.Where(i => i.TeamId == m.LosingTeamId).FirstOrDefault();
                        match.LosingTeam = tt.GetTeam(lt.TeamId);

                        match.WinningTeamStats = context.PlayerMatchRef.Where(i => i.MatchId == m.MatchId && match.WinningTeam.ids.Contains(i.PlayerId)).OrderBy(o => o.PlayerId).ToList();
                        match.LosingTeamStats  = context.PlayerMatchRef.Where(i => i.MatchId == m.MatchId && match.LosingTeam.ids.Contains(i.PlayerId)).OrderBy(o => o.PlayerId).ToList();

                        match.PlayerNames    = new List <String>();
                        match.ChampionImages = new List <String>();
                        match.ChampionBans   = new List <String>();
                        match.WinningTeamStats.ForEach((player) =>
                        {
                            match.PlayerNames.Add(context.Player.Where(x => player.PlayerId == x.PlayerId).Select(l => l.PlayerIgn).FirstOrDefault());
                            match.ChampionImages.Add(context.Champion.Where(x => player.ChampionPlayedId == x.ChampionId).Select(l => l.ChampionImage).FirstOrDefault());
                            match.ChampionBans.Add(context.Champion.Where(x => player.ChampionBannedId == x.ChampionId).Select(l => l.ChampionImage).FirstOrDefault());
                        });

                        match.PlayerNames2    = new List <String>();
                        match.ChampionImages2 = new List <String>();
                        match.ChampionBans2   = new List <String>();
                        match.LosingTeamStats.ForEach((player) =>
                        {
                            match.PlayerNames2.Add(context.Player.Where(x => player.PlayerId == x.PlayerId).Select(l => l.PlayerIgn).FirstOrDefault());
                            match.ChampionImages2.Add(context.Champion.Where(x => player.ChampionPlayedId == x.ChampionId).Select(l => l.ChampionImage).FirstOrDefault());
                            match.ChampionBans2.Add(context.Champion.Where(x => player.ChampionBannedId == x.ChampionId).Select(l => l.ChampionImage).FirstOrDefault());
                        });

                        Tournament t = context.Tournament.Where(x => x.TournamentId == m.TournamentId).FirstOrDefault();
                        match.TournamentID   = t.TournamentId;
                        match.TournamentName = t.TournamentName;

                        dbContextTransaction.Commit();
                        return(match);
                    }
                    catch (Exception e)
                    {
                        MatchStructure match = new MatchStructure();
                        match.error   = 1;
                        match.message = e.ToString();
                        dbContextTransaction.Rollback();
                        return(match);
                    }
                }
            }
        }