public static void Seed(Top25NBAPlayersContext context)
        {
            if (context.Users.FirstOrDefault() == null)
            {
                AppUser newUser1 = new AppUser("Admin1997", "https://cdn1.iconfinder.com/data/icons/user-pictures/101/malecostume-512.png", "passw0rd", 0);

                AppUser newUser2 = new AppUser("Admin96", "https://cdn0.iconfinder.com/data/icons/user-pictures/100/matureman1-512.png", "passw0rd", 0);

                context.Users.AddAsync(newUser1);

                context.Users.AddAsync(newUser2);

                context.SaveChangesAsync();

                return;
            }
        }
示例#2
0
        //Pass your context as an argument so at runtime you would be able to seed data during runtime. Has access to method in the context class properties.
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, Top25NBAPlayersContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseSession();

            app.UseHttpsRedirection();

            app.UseCors(builder => builder.AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin());

            app.UseMvc();
        }
示例#3
0
 public PlayerRepo(Top25NBAPlayersContext context)
 {
     _context = context;
 }
示例#4
0
        public static void Seed(Top25NBAPlayersContext context)
        {
            //If the player's table does not contain data add data to the database.
            if (context.Players.FirstOrDefault() == null)
            {
                Player newPlayer = new Player(
                    name: "Lebron James",
                    avatar: "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/1966.png&w=350&h=254",
                    jerseyNumber: 23,
                    teamId: Guid.Parse("08d6a679-7eed-bf9f-3060-d7147c4333bd"),
                    mvps: 4,
                    allstars: 15,
                    championships: 3,
                    seasonPoints: 27.1,
                    seasonAssists: 8.1,
                    seasonRebounds: 8.6,
                    seasonFieldGoalPercentage: 51.3,
                    deletedInd: null
                    );

                Player newPlayer2 = new Player(
                    name: "Kyrie Irving",
                    avatar: "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/6442.png&w=350&h=254",
                    jerseyNumber: 11,
                    teamId: Guid.Parse("08d6a679-7efd-06be-d957-e8ef2c3e0a7b"),
                    mvps: 0,
                    allstars: 6,
                    championships: 1,
                    seasonPoints: 23.5,
                    seasonAssists: 6.9,
                    seasonRebounds: 4.9,
                    seasonFieldGoalPercentage: 49.8,
                    deletedInd: null
                    );

                Player newPlayer3 = new Player(
                    name: "Chris Paul",
                    avatar: "https://jordansrmysole.com/wp-content/uploads/2018/01/Chris-Paul.png",
                    jerseyNumber: 3,
                    teamId: Guid.Parse("08d6a679-7efd-14c7-488b-cddb122995db"),
                    mvps: 0,
                    allstars: 9,
                    championships: 0,
                    seasonPoints: 15.5,
                    seasonAssists: 8.3,
                    seasonRebounds: 4.5,
                    seasonFieldGoalPercentage: 41.7,
                    deletedInd: null
                    );

                Player newPlayer4 = new Player(
                    name: "James Harden",
                    avatar: "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3992.png&w=350&h=254",
                    jerseyNumber: 13,
                    teamId: Guid.Parse("08d6a679-7efd-14c7-488b-cddb122995db"),
                    mvps: 1,
                    allstars: 7,
                    championships: 0,
                    seasonPoints: 36.6,
                    seasonAssists: 7.5,
                    seasonRebounds: 6.5,
                    seasonFieldGoalPercentage: 44.0,
                    deletedInd: null
                    );

                Player newPlayer5 = new Player(
                    name: "Dwyane Wade",
                    avatar: "https://b.fssta.com/uploads/application/nba/headshots/1135.vresize.350.425.medium.42.png",
                    jerseyNumber: 3,
                    teamId: Guid.Parse("08d6a679-7efd-124a-c9c5-3fb707ab3243"),
                    mvps: 0,
                    allstars: 13,
                    championships: 3,
                    seasonPoints: 14.2,
                    seasonAssists: 4.3,
                    seasonRebounds: 3.7,
                    seasonFieldGoalPercentage: 43.7,
                    deletedInd: null
                    );

                Player newPlayer6 = new Player(
                    name: "Giannis Antetokounmpo",
                    avatar: "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3032977.png&w=350&h=254",
                    jerseyNumber: 34,
                    teamId: Guid.Parse("08d6a679-7efd-1383-90d7-e946d70ef236"),
                    mvps: 0,
                    allstars: 3,
                    championships: 0,
                    seasonPoints: 27.0,
                    seasonAssists: 6.0,
                    seasonRebounds: 12.6,
                    seasonFieldGoalPercentage: 58.0,
                    deletedInd: null
                    );

                Player[] players = new[] { newPlayer, newPlayer2, newPlayer3, newPlayer4, newPlayer5, newPlayer6 };
                context.Players.AddRange(players);
                context.SaveChanges();
            }
        }
        public static void Seed(Top25NBAPlayersContext context)
        {
            try
            {
                if (context.Teams.FirstOrDefault() == null)
                {
                    Team newTeam1 = new Team(

                        name: "Los Angeles Lakers",
                        logo: "https://www.nba.com/.element/img/1.0/teamsites/logos/teamlogos_500x500/lal.png",
                        greatestPlayer: "Magic Johnson",
                        lastChampionship: 2010,
                        championships: 16,
                        deletedInd: 0
                        );

                    Team newTeam2 = new Team(
                        name: "Boston Celtics",
                        logo: "http://content.sportslogos.net/logos/6/213/full/pphdqx7bfbbbumpehh7telq1h.png",
                        greatestPlayer: "Bill Russell",
                        lastChampionship: 2008,
                        championships: 17,
                        deletedInd: 0
                        );


                    Team newTeam3 = new Team(
                        name: "Cleveland Cavaliers",
                        logo: "https://pbs.twimg.com/profile_images/1092836368529719296/PdqyrDND_400x400.jpg",
                        greatestPlayer: "Lebron James",
                        lastChampionship: 2016,
                        championships: 1,
                        deletedInd: 0
                        );

                    Team newTeam4 = new Team(
                        name: "Miami Heat",
                        logo: "https://wwwcache.wralsportsfan.com/asset/basketball/nba/2010/06/15/7790661/122496-heat-600x400.jpg",
                        greatestPlayer: "Dwyane Wade",
                        lastChampionship: 2013,
                        championships: 3,
                        deletedInd: 0
                        );

                    Team newTeam5 = new Team(
                        name: "Los Angeles Clippers",
                        logo: "https://a1.espncdn.com/combiner/i?img=%2Fphoto%2F2015%2F0616%2Fnba_ClipsLogo_1296x1296.png",
                        greatestPlayer: "Chris Paul",
                        lastChampionship: null,
                        championships: 0,
                        deletedInd: 0
                        );

                    Team newTeam6 = new Team(
                        name: "Milwaukee Bucks",
                        logo: "http://www.trbimg.com/img-559ffd90/turbine/ct-high-school-logo-nba-bucks-20150710",
                        greatestPlayer: "Kareem Abdul Jabbar",
                        lastChampionship: 1971,
                        championships: 1,
                        deletedInd: 0
                        );

                    Team newTeam7 = new Team(
                        name: "San Antonio Spurs",
                        logo: "http://content.sportslogos.net/logos/6/233/full/827.png",
                        greatestPlayer: "Tim Duncan",
                        lastChampionship: 2014,
                        championships: 5,
                        deletedInd: 0
                        );

                    Team newTeam8 = new Team(
                        name: "Houston Rockets",
                        logo: "http://www.bbqsuperstars.com/wp-content/uploads/2013/06/HoustonRockets_PAM04a_2009_SCC_SRGB.png",
                        greatestPlayer: "Hakeem Olajuwon",
                        lastChampionship: 1995,
                        championships: 2,
                        deletedInd: 0
                        );

                    Team[] teamsToAdd = { newTeam1, newTeam2, newTeam3, newTeam4, newTeam5, newTeam6, newTeam7, newTeam8 };
                    //Team[] teamsToAdd = { newTeam1, newTeam2 };

                    context.Teams.AddRange(teamsToAdd);

                    context.SaveChanges();
                }
            } catch (Exception ex)
            {
                Exception sampleEx = ex;
                Console.Write(ex);
            }
        }