예제 #1
0
        public static void AddTeam()
        {
            var context = new GamepediaContext();

            byte[] image1 = File.ReadAllBytes(@"C:\Users\Jacob\source\repos\myGamepedia\UI\Images\NiPlogo.jpg");
            byte[] image2 = File.ReadAllBytes(@"C:\Users\Jacob\source\repos\myGamepedia\UI\Images\fnatic-logo-font.png");

            Team team1 = new Team();

            team1.Name        = "Ninjas In Pyjamas";
            team1.Description = "Counter-Strike Team";
            team1.TeamLogo    = image1;
            team1.Founded     = new DateTime(1999, 6, 21);
            team1.CountryId   = 1;

            Team team2 = new Team();

            team2.Name        = "Fnatic";
            team2.Description = "Counter-Strike Team";
            team2.TeamLogo    = image2;
            team2.Founded     = new DateTime(1995, 10, 22);
            team2.CountryId   = 1;

            context.Teams.AddRange(team1, team2);
            context.SaveChanges();
        }
        public static void DisplayCountriesAndMore()
        {
            var context   = new GamepediaContext();
            var countries = context.Countries
                            .Include(m => m.Players)
                            .Include(m => m.Teams)
                            .Include(m => m.Tournaments)
                            .ToList();

            Console.WriteLine("\n\n\n==============\n");
            foreach (var country in countries)
            {
                Console.WriteLine(country.Name);
                foreach (var player in country.Players)
                {
                    Console.WriteLine("has this player: " + player.NickName);
                }
                foreach (var team in country.Teams)
                {
                    Console.WriteLine("\t and this team: " + team.Name);
                }
                foreach (var tournament in country.Tournaments)
                {
                    Console.WriteLine("\t\t have hosted this tournament: " + tournament.TournamentName + " " + tournament.EndDate.Year);
                    Console.WriteLine("\t\t\t  and the team that won was: " + tournament.TheTeam.Name);
                }
            }
            Console.ReadKey();
        }
        public static void DisplayTeamsAndPlayersAndMore()
        {
            var context = new GamepediaContext();
            var teams   = context.Teams
                          .Include(m => m.Players)
                          .ThenInclude(ma => ma.Player)
                          .Include(m => m.Tournaments)
                          .ToList();

            Console.WriteLine("\n\n\n=======================\n");
            foreach (var team in teams)
            {
                Console.WriteLine(team.Name);
                if (null != team.Tournaments)
                {
                    Console.WriteLine("Have won this many tournaments: " + team.Tournaments.Count);
                }
                else
                {
                    Console.WriteLine("have not won any tournaments");
                }
                foreach (var player in team.Players)
                {
                    Console.WriteLine("\t" + " with this player: " + player.Player.FirstName + " " + player.Player.LastName + ", NickName: " + player.Player.NickName);
                }
            }
        }
        public static void UpdateSingle()
        {
            var context = new GamepediaContext();
            var map     = context.Maps.Find(1);

            map.Name = "De_Cbblestone";
            context.SaveChanges();
        }
        public static void GetLastTournament()
        {
            var context = new GamepediaContext();

            var tournament = context.Tournaments.LastOrDefault(m => m.StartDate.Year == 2016);

            Console.WriteLine(tournament.TournamentName);
        }
        public static void ProjectionLoading()
        {
            var context          = new GamepediaContext();
            var projectedCountry = context.Countries.Select(a =>
                                                            new { a.Name, PlayerCount = a.Players.Count })
                                   .Where(a => a.PlayerCount > 0).ToList();

            projectedCountry.ForEach(a => Console.WriteLine(a.Name + " has this many players: " + a.PlayerCount));
        }
        public static void DeleteOne()
        {
            var context = new GamepediaContext();

            var player = context.Players.Find(3);

            context.Players.Remove(player);
            context.SaveChanges();
        }
예제 #8
0
        public static async Task <List <Team> > SelectTeamAndPlayersWithAsync()
        {
            var context = new GamepediaContext();
            var result  = await context.Teams
                          .Include(m => m.Players)
                          .ThenInclude(ma => ma.Player)
                          .ToListAsync();

            return(result);
        }
        public static void DeletePlayerFromTeam()
        {
            var context    = new GamepediaContext();
            var teamplayer = context.TeamPlayers
                             .Where(tp => tp.PlayerId == 4 && tp.TeamId == 2)
                             .FirstOrDefault();

            context.Remove(teamplayer);
            context.SaveChanges();
        }
        public static void ProjectionLoading2()
        {
            var context             = new GamepediaContext();
            var projectedTournament = context.Tournaments.Select(a =>
                                                                 new { a.TournamentName, MapCount = a.Maps.Count })
                                      .Where(a => a.MapCount > 1 && a.TournamentName.StartsWith("IEM"))
                                      .ToList();

            projectedTournament.ForEach(pa => Console.WriteLine(pa.TournamentName + " has this many maps: " + pa.MapCount));
        }
        public static void DeleteTournamentByCountryId()
        {
            var context    = new GamepediaContext();
            var tournament = context.Tournaments
                             .Where(t => t.CountryId == 2)
                             .FirstOrDefault();

            context.Remove(tournament);
            context.SaveChanges();
        }
        public static void UpdateMany()
        {
            var    context        = new GamepediaContext();
            string tournamentName = "IEM";
            var    tournaments    = context.Tournaments.Where(m => m.TournamentName.StartsWith(tournamentName)).ToList();

            tournaments.ForEach(m => m.StartDate = new DateTime(2017, 8, 22));
            tournaments.ForEach(m => m.EndDate   = new DateTime(2017, 8, 26));
            context.SaveChanges();
        }
        public static void DeleteMany()
        {
            var context = new GamepediaContext();

            string teamName = "fnatic";
            var    teams    = context.Teams.Where(m => m.Name.StartsWith(teamName)).ToList();

            context.Teams.RemoveRange(teams);
            context.SaveChanges();
        }
예제 #14
0
        public static async Task <List <Tournament> > SelectTournamentAndMapsWithAsync()
        {
            var context = new GamepediaContext();
            var result  = await context.Tournaments
                          .Include(x => x.Maps)
                          .ThenInclude(xa => xa.Map)
                          .ToListAsync();

            return(result);
        }
        public static void SelectUsingStoredProcedure()
        {
            var    context   = new GamepediaContext();
            string searchMap = "De";
            var    maps      = context.Maps.FromSql("EXEC FindMapsByName {0}", searchMap).ToList();

            foreach (var map in maps)
            {
                Console.WriteLine(map.Name);
            }
        }
예제 #16
0
        public static void AddMap()
        {
            var context = new GamepediaContext();

            Map map = new Map {
                Name = "De_Inferno", Launch = new DateTime(1998, 6, 12)
            };

            context.Maps.Add(map);
            context.SaveChanges();
        }
예제 #17
0
        public static void AddTournamentMap()
        {
            var context = new GamepediaContext();

            var map        = context.Maps.Find(5);
            var tournament = context.Tournaments.Find(5);

            context.Add(new TournamentMap {
                Map = map, Tournament = tournament
            });
            context.SaveChanges();
        }
        public static void GetAllPlayers()
        {
            var context = new GamepediaContext();

            var players1 = context.Players.ToList();
            var players2 = context.Players.Where(m => m.NickName.StartsWith("f")).ToList();

            foreach (var player in players1)
            {
                Console.WriteLine(player.FirstName);
            }
        }
예제 #19
0
        public static void AddTeamPlayers()
        {
            var context = new GamepediaContext();

            var player = context.Players.Find(2);
            var team   = context.Teams.Find(2);

            context.Add(new TeamPlayer {
                Team = team, Player = player
            });
            context.SaveChanges();
        }
        public static void SelectPlayersWithOrderbyAndStartwith()
        {
            var context = new GamepediaContext();
            var players = context.Players.FromSql("SELECT * FROM Players")
                          .Where(m => m.NickName.StartsWith("f"))
                          .OrderBy(m => m.FirstName)
                          .ToList();

            foreach (var player in players)
            {
                Console.WriteLine(player.LastName);
            }
        }
예제 #21
0
        public static void AddCountry()
        {
            var context = new GamepediaContext();

            byte[] image1 = File.ReadAllBytes(@"C:\Users\Jacob\source\repos\myGamepedia\UI\Images\Swedishflag.jpg");
            byte[] image2 = File.ReadAllBytes(@"C:\Users\Jacob\source\repos\myGamepedia\UI\Images\Canadaflag.jpg");

            Country country1 = new Country {
                Name = "Sweden", CountryCode = "SE", FlagImage = image1
            };
            Country country2 = new Country {
                Name = "Canada", CountryCode = "CA", FlagImage = image2
            };

            context.Countries.AddRange(country1, country2);
            context.SaveChanges();
        }
예제 #22
0
        public static void AddPlayer()
        {
            var context = new GamepediaContext();

            Player player1 = new Player
            {
                FirstName = "Patrik",
                LastName  = "Lindberg",
                BirthDate = new DateTime(1988, 5, 15),
                NickName  = "f0rest",
                Role      = "Rifler",
                Status    = "Active",
                CountryId = 1
            };

            context.Players.Add(player1);
            context.SaveChanges();
        }
예제 #23
0
        public static void AddPlayersToTeam()
        {
            var context = new GamepediaContext();

            var team    = context.Teams.Find(2);
            var players = context.Players.ToList();

            foreach (var player in players)
            {
                if (player.FirstName == "Freddy" || player.FirstName == "Jesper")
                {
                    context.TeamPlayers.Add(new TeamPlayer {
                        TeamId = team.Id, PlayerId = player.Id
                    });
                }
            }
            context.SaveChanges();
        }
예제 #24
0
        public static void AddTournament()
        {
            var context = new GamepediaContext();

            Tournament tournament = new Tournament
            {
                Tier           = "Major",
                GameName       = "Counter-Strike",
                TournamentName = "DreamHack Open",
                StartDate      = new DateTime(2017, 8, 22),
                EndDate        = new DateTime(2017, 8, 28),
                PriceMoney     = 1000000,
                TeamId         = 1,
                CountryId      = 1
            };

            context.Tournaments.Add(tournament);
            context.SaveChanges();
        }