Beispiel #1
0
 public void CreateStage(Season currentSeason, DateTime startDate)
 {
     _leagueContext.Entry(currentSeason).Collection(s => s.UserSeasons).Load();
     _currentSeason = currentSeason;
     CreateGroupsWithParticipants();
     CreateSchedule(startDate);
     _leagueContext.SaveChanges();
 }
Beispiel #2
0
 public void Create(TimeSpan intervalBetweenRounds)
 {
     _leagueContext.Seasons.Add(new Season()
     {
         IntervalBetweenRounds = intervalBetweenRounds
     });
     _leagueContext.SaveChanges();
 }
Beispiel #3
0
        private async Task CreateOAuthTicket(OAuthCreatingTicketContext context)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint);

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken);

            var response = await context.Backchannel.SendAsync(request, context.HttpContext.RequestAborted);

            response.EnsureSuccessStatusCode();

            context.HttpContext.Response.Cookies.Append("token", context.AccessToken);

            var user = JObject.Parse(await response.Content.ReadAsStringAsync());

            context.RunClaimActions(user);

            LeagueContext leagueContext = context.HttpContext.RequestServices.GetService <LeagueContext>();
            int           id            = int.Parse((string)user["id"]);
            User          dbUser        = leagueContext.Users.Find(id);
            Role          role          = null;

            if (dbUser == null)
            {
                role   = leagueContext.Roles.First(r => r.Name == RoleConstants.User);
                dbUser = new User()
                {
                    Id        = id,
                    BattleTag = context.Identity.Name,
                    Role      = role
                };
                leagueContext.Users.Add(dbUser);
                leagueContext.SaveChanges();
            }
            if (dbUser.ProfileId == null)
            {
                Profile profile = await GetFullProfileAsync(dbUser, context, leagueContext);

                if (profile != null)
                {
                    leagueContext.Profiles.Add(profile);
                    dbUser.ProfileId = profile.Id;
                    leagueContext.Attach(dbUser);
                    leagueContext.Entry(dbUser).Property(u => u.ProfileId).IsModified = true;
                    leagueContext.SaveChanges();
                    SetHasProfileClaimAsTrue(context);
                }
            }
            else
            {
                SetHasProfileClaimAsTrue(context);
            }
            role = role ?? leagueContext.Roles.Find(dbUser.RoleId);
            context.Identity.AddClaim(new Claim(ClaimsIdentity.DefaultRoleClaimType, role.Name));
        }
        public ActionResult Create([Bind(Include = "PlayerID,FirstName,LastName")] Player player)
        {
            if (ModelState.IsValid)
            {
                db.Players.Add(player);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(player));
        }
Beispiel #5
0
        public int CreateMatch(DateTime dateOfMatch, int player1, int player2, MatchWinner winner)
        {
            ValidateMatchIsNotHistoric(dateOfMatch);

            if (player1 == player2)
            {
                throw new Exception("Player 1 and Player 2 must be different players");
            }

            int   lastMatchDayOrder = db.Matches.Where(m => DbFunctions.TruncateTime(m.DateOfMatch) == dateOfMatch.Date).Max(m => (int?)m.DayMatchOrder) ?? 0;
            int   matchDayOrder     = lastMatchDayOrder + ORDER_VALUE_SPACING;
            Match match             = new Match()
            {
                DateOfMatch = dateOfMatch, DayMatchOrder = matchDayOrder, MatchParticipations = new List <MatchParticipation>()
            };

            var player1LadderRank = GetCurrentLadderRank(player1, dateOfMatch.Year, dateOfMatch.Month);
            var player2LadderRank = GetCurrentLadderRank(player2, dateOfMatch.Year, dateOfMatch.Month);

            if (player1LadderRank == player2LadderRank)
            {
                player2LadderRank++;
            }

            match.MatchParticipations.Add(CreateMatchParticipation(player1, player2, (winner == MatchWinner.Player1), dateOfMatch, player1LadderRank, player2LadderRank));
            match.MatchParticipations.Add(CreateMatchParticipation(player2, player1, (winner == MatchWinner.Player2), dateOfMatch, player2LadderRank, player1LadderRank));

            db.Matches.Add(match);
            db.SaveChanges();

            return(match.MatchID);
        }
Beispiel #6
0
        public IActionResult Create([FromBody] League item)
        {
            if (item == null || !item.SportId.HasValue)
            {
                return(BadRequest());
            }

            var league = new League
            {
                Id       = item.Id,
                Name     = item.Name,
                Category = _sportContext.Sports.FirstOrDefault(x => x.Id == item.SportId.Value),
            };

            _context.Leagues.Add(league);
            _context.SaveChanges();

            return(CreatedAtRoute("GetLeague", new { id = item.Id }, item));
        }
 public async virtual Task <IActionResult> Users([FromForm] User[] users)
 {
     foreach (User user in users)
     {
         User dbUser = _leagueContext.Users.Find(user.Id);
         dbUser.RoleId = user.RoleId;
     }
     _leagueContext.SaveChanges();
     return(View(await GetRolesAsync()));
 }
        private void CreateRound(Season currentSeason, DateTime date)
        {
            PlayoffsRound firstPlayoffsRound = new PlayoffsRound
            {
                EventDate = date
            };

            currentSeason.PlayoffsRounds.Add(firstPlayoffsRound);
            _leagueContext.SaveChanges();
            _roundId = firstPlayoffsRound.Id;
        }
 public void CreateMatch(int roundId, int firstPlayerId, int secondPlayerId)
 {
     _leagueContext.Matches.Add(
         new Match
     {
         RoundId        = roundId,
         FirstPlayerId  = firstPlayerId,
         SecondPlayerId = secondPlayerId
     });
     _leagueContext.SaveChanges();
 }
Beispiel #10
0
        public static void Update(params Entity[] entities)
        {
            using (var context = new LeagueContext(options))
            {
                foreach (var entity in entities)
                {
                    context.Update(entity);
                }

                context.SaveChanges();
            }
        }
        public virtual ActionResult Edit([FromForm] Match match)
        {
            if (!ModelState.IsValid)
            {
                match = LoadMatchWithPlayers(match.MatchId);
                return(View(match));
            }

            _leagueContext.Attach(match);
            _leagueContext.Entry(match).Property(m => m.FirstPlayerWins).IsModified  = true;
            _leagueContext.Entry(match).Property(m => m.SecondPlayerWins).IsModified = true;
            _leagueContext.SaveChanges();
            return(RedirectToAction(MVC.Season.Schedule()));
        }
        public static LeagueContext SeedDbWithFiveSummoners(
            this LeagueContext context)
        {
            context.Summoners.AddRange(
                new Summoner
            {
                ID                = 1,
                SummonerName      = "Peasant Slayer",
                SummonerLevel     = 48,
                ServerID          = 2,
                ProfileIconNumber = 2
            },
                new Summoner
            {
                ID                = 2,
                SummonerName      = "Shimeshugar",
                SummonerLevel     = 99,
                ServerID          = 1,
                ProfileIconNumber = 2
            },
                new Summoner
            {
                ID                = 3,
                SummonerName      = "Koomuch",
                SummonerLevel     = 90,
                ServerID          = 1,
                ProfileIconNumber = 2
            },
                new Summoner
            {
                ID                = 4,
                SummonerName      = "ubnix",
                SummonerLevel     = 47,
                ServerID          = 1,
                ProfileIconNumber = 2
            },
                new Summoner
            {
                ID                = 5,
                SummonerName      = "Major Alexander",
                SummonerLevel     = 60,
                ServerID          = 2,
                ProfileIconNumber = 2
            }
                );

            context.SaveChanges();

            return(context);
        }
Beispiel #13
0
        public static void Insert(params Entity[] entities)
        {
            using (var context = new LeagueContext(options))
            {
                foreach (var entity in entities)
                {
                    if (entity.Id == 0)
                    {
                        context.Add(entity);
                    }
                }

                context.SaveChanges();
            }
        }
        public void Create(int groupId, IRound <int, Matchup <int> > groupRound, DateTime date)
        {
            GroupRound dbGroupRound = new GroupRound
            {
                GroupId   = groupId,
                EventDate = date
            };

            _leagueContext.GroupRounds.Add(dbGroupRound);
            _leagueContext.SaveChanges();

            foreach (Matchup <int> matchup in groupRound)
            {
                _matchService.CreateMatch(dbGroupRound.Id, matchup.FirstPlayer, matchup.SecondPlayer);
            }
        }
        private static void SeedMatchResult(LeagueContext leagueContext, Randomizer randomizer, Match match)
        {
            byte firstPlayerWins;
            byte secondPlayerWins;

            if (randomizer.Bool())
            {
                SeedMatchResult(randomizer, out firstPlayerWins, out secondPlayerWins);
            }
            else
            {
                SeedMatchResult(randomizer, out secondPlayerWins, out firstPlayerWins);
            }
            match.FirstPlayerWins  = firstPlayerWins;
            match.SecondPlayerWins = secondPlayerWins;
            leagueContext.Entry(match).Property(m => m.FirstPlayerWins).IsModified  = true;
            leagueContext.Entry(match).Property(m => m.SecondPlayerWins).IsModified = true;
            leagueContext.SaveChanges();
        }
Beispiel #16
0
        public void MapChampion(List <TempChampion> champions)
        {
            context.Database.BeginTransaction();
            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT Champions ON");

            foreach (var champ in champions)
            {
                var dbChamp = new Champion
                {
                    ID                  = champ.Key,
                    ChampionName        = champ.Name,
                    ChampionTitle       = champ.Title,
                    ChampionDescription = champ.Blurb ?? string.Empty
                };
                context.Add(dbChamp);

                var dbInfo = new ChampionStats
                {
                    ResourceType            = champ.Partype,
                    Attack                  = champ.Info.Attack,
                    Defense                 = champ.Info.Defense,
                    Magic                   = champ.Info.Magic,
                    Difficulty              = champ.Info.Difficulty,
                    HitPoints               = champ.Stats.Hp,
                    HitPointsPerLevel       = champ.Stats.HpPerLevel,
                    ManaPoints              = champ.Stats.Mp,
                    ManaPointsPerLevel      = champ.Stats.MpPerLevel,
                    MoveSpeed               = champ.Stats.Movespeed,
                    Armor                   = champ.Stats.Armor,
                    ArmorPerLevel           = champ.Stats.ArmorPerLevel,
                    SpellBlock              = champ.Stats.Spellblock,
                    SpellBlockPerLevel      = champ.Stats.SpellblockPerLevel,
                    AttackRange             = champ.Stats.AttackRange,
                    HitPointsRegen          = champ.Stats.HpRegen,
                    HitPointsRegenPerLevel  = champ.Stats.HpRegenPerLevel,
                    ManaPointsRegen         = champ.Stats.MpRegen,
                    ManaPointsRegenPerLevel = champ.Stats.MpRegenPerLevel,
                    CritChance              = champ.Stats.Crit,
                    CritChancePerLevel      = champ.Stats.CritPerLevel,
                    AttackDamage            = champ.Stats.AttackDamage,
                    AttackDamagePerLevel    = champ.Stats.AttackDamagePerLevel,
                    ChampionID              = champ.Key
                };
                context.Add(dbInfo);

                foreach (var tag in champ.Tags)
                {
                    int tagID = 0;

                    switch (tag)
                    {
                    case "Fighter":
                        tagID = 1;
                        break;

                    case "Tank":
                        tagID = 2;
                        break;

                    case "Mage":
                        tagID = 3;
                        break;

                    case "Assassin":
                        tagID = 4;
                        break;

                    case "Support":
                        tagID = 5;
                        break;

                    case "Marksman":
                        tagID = 6;
                        break;
                    }

                    context.Add(new ChampionTags
                    {
                        ChampionID = champ.Key,
                        TagID      = tagID
                    });
                }
            }

            context.SaveChanges();
            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT Champions OFF;");
            context.Database.CommitTransaction();
        }
Beispiel #17
0
        public static void Seed(LeagueContext context)
        {
            context.Database.EnsureCreated();
            //context.Database.ExecuteSqlCommand("SET IDENTITY INSERT dbo.Teams ON");
            //context.Database.ExecuteSqlCommand("SET IDENTITY INSERT dbo.Players ON");
            //context.Database.ExecuteSqlCommand("SET IDENTITY INSERT dbo.Matches ON");
            context.SaveChanges();

            var teams = new List <TeamRequest>
            {
                new TeamRequest
                {
                    Name = "Legia",
                    City = "Warszawa"
                },
                new TeamRequest
                {
                    Name = "Wisla",
                    City = "Krakow"
                },
                new TeamRequest
                {
                    Name = "Slask",
                    City = "Wroclaw"
                }
            };

            var players = new List <PlayerRequest>
            {
                new PlayerRequest
                {
                    FirstName = "Jack",
                    SurName   = "Reacher",
                    Age       = 30,
                    TeamId    = 1
                },
                new PlayerRequest
                {
                    FirstName = "John",
                    SurName   = "Carter",
                    Age       = 35,
                    TeamId    = 1
                },
                new PlayerRequest
                {
                    FirstName = "Robert",
                    SurName   = "DeNirro",
                    Age       = 30,
                    TeamId    = 2
                },
                new PlayerRequest
                {
                    FirstName = "Jack",
                    SurName   = "Strong",
                    Age       = 38,
                    TeamId    = 3
                }
            };

            var matches = new List <MatchRequest>
            {
                new MatchRequest
                {
                    HomeTeamId     = 1,
                    GuestTeamId    = 2,
                    HomeTeamGoals  = 1,
                    GuestTeamGoals = 2
                },
                new MatchRequest
                {
                    HomeTeamId     = 3,
                    GuestTeamId    = 1,
                    HomeTeamGoals  = 1,
                    GuestTeamGoals = 2
                },
                new MatchRequest
                {
                    HomeTeamId     = 2,
                    GuestTeamId    = 3,
                    HomeTeamGoals  = 1,
                    GuestTeamGoals = 1
                },
            };

            TeamRepository    teamRepositiory   = new TeamRepository(context);
            PlayerRepositiory playerRepositiory = new PlayerRepositiory(context);
            MatchRepository   matchRepository   = new MatchRepository(context);

            LeagueInputService leagueInputService = new LeagueInputService(teamRepositiory, playerRepositiory, matchRepository);

            foreach (TeamRequest teamRequest in teams)
            {
                leagueInputService.CreateTeam(teamRequest);
            }

            foreach (PlayerRequest playerRequest in players)
            {
                leagueInputService.AddPlayer(playerRequest);
            }

            foreach (MatchRequest matchRequest in matches)
            {
                leagueInputService.PlayMatch(matchRequest);
            }

            //context.Database.ExecuteSqlCommand("SET IDENTITY INSERT dbo.Events OFF");
            //context.Database.ExecuteSqlCommand("SET IDENTITY INSERT dbo.Persons OFF");
            //context.Database.ExecuteSqlCommand("SET IDENTITY INSERT dbo.PersonEvents OFF");
            context.SaveChanges();
        }
Beispiel #18
0
        public static void Initialize(LeagueContext context)
        {
            //context.Database.EnsureCreated();

            // Look for any Teams.
            if (context.Team.Any())
            {
                return;   // DB has been seeded
            }

            var coaches = new Coach[]
            {
                new Coach {
                    ID = 1, FirstName = "Rick", LastName = "Tocchet", HireDate = DateTime.Parse("2015-05-28")
                },
                new Coach {
                    ID = 2, FirstName = "Peter", LastName = "DeBoer", HireDate = DateTime.Parse("2017-04-11")
                },
                new Coach {
                    ID = 9, FirstName = "Joel", LastName = "Quenneville", HireDate = DateTime.Parse("2008-10-16")
                }
            };

            foreach (Coach c in coaches)
            {
                context.Coach.Add(c);
            }
            context.SaveChanges();


            var conferences = new Conference[]
            {
                new Conference {
                    ID = 1, ConferenceName = "Western"
                },
                new Conference {
                    ID = 2, ConferenceName = "Eastern"
                }
            };

            foreach (Conference c in conferences)
            {
                context.Conference.Add(c);
            }
            context.SaveChanges();


            var divisions = new Division[]
            {
                new Division {
                    ID = 1, DivisionName = "Pacific"
                },
                new Division {
                    ID = 2, DivisionName = "Central"
                },
                new Division {
                    ID = 3, DivisionName = "Metropolitan"
                },
                new Division {
                    ID = 4, DivisionName = "Atlantic"
                }
            };

            foreach (Division d in divisions)
            {
                context.Division.Add(d);
            }
            context.SaveChanges();


            var teams = new Team[]
            {
                new Team {
                    TeamName = "Arizona Coyotes", TeamLocation = "Arizona", CoachID = 1, DivisionID = 1, ConferenceID = 1
                },
                new Team {
                    TeamName = "San Jose Sharks", TeamLocation = "California", CoachID = 2, DivisionID = 1, ConferenceID = 1
                },
                new Team {
                    TeamName = "Anaheim Ducks", TeamLocation = "California", /*CoachID = ,*/ DivisionID = 1, ConferenceID = 1
                },
                new Team {
                    TeamName = "Calgary Flames", TeamLocation = "Alberta, Canada", /*CoachID = ,*/ DivisionID = 1, ConferenceID = 1
                },
                new Team {
                    TeamName = "Edmonton Oilers", TeamLocation = "Alberta, Canada", /*CoachID = ,*/ DivisionID = 1, ConferenceID = 1
                },
                new Team {
                    TeamName = "Los Angeles Kings", TeamLocation = "California", /*CoachID = ,*/ DivisionID = 1, ConferenceID = 1
                },
                new Team {
                    TeamName = "Vancouver Canucks", TeamLocation = "British Columbia, Canada", /*CoachID = ,*/ DivisionID = 1, ConferenceID = 1
                },
                new Team {
                    TeamName = "Vegas Golden Knights", TeamLocation = "Nevada", /*CoachID = ,*/ DivisionID = 1, ConferenceID = 1
                },
                new Team {
                    TeamName = "Chicago Blackhawks", TeamLocation = "Illinois", CoachID = 9, DivisionID = 2, ConferenceID = 1
                },
                new Team {
                    TeamName = "Colorado Avalanche", TeamLocation = "Colorado", /*CoachID = ,*/ DivisionID = 2, ConferenceID = 1
                },
                new Team {
                    TeamName = "Dallas Stars", TeamLocation = "Texas", /*CoachID = ,*/ DivisionID = 2, ConferenceID = 1
                },
                new Team {
                    TeamName = "Minnesota Wild", TeamLocation = "Minnesota", /*CoachID = ,*/ DivisionID = 2, ConferenceID = 1
                },
                new Team {
                    TeamName = "Nashville Predators", TeamLocation = "Tennessee", /*CoachID = ,*/ DivisionID = 2, ConferenceID = 1
                },
                new Team {
                    TeamName = "St. Louis Blues", TeamLocation = "Missouri", /*CoachID = ,*/ DivisionID = 2, ConferenceID = 1
                },
                new Team {
                    TeamName = "Winnipeg Jets", TeamLocation = "Manitoba, Canada", /*CoachID = ,*/ DivisionID = 2, ConferenceID = 1
                },
                new Team {
                    TeamName = "Carolina Hurricanes", TeamLocation = "North Carolina", /*CoachID = ,*/ DivisionID = 3, ConferenceID = 2
                },
                new Team {
                    TeamName = "Columbus Blue Jackets", TeamLocation = "Ohio", /*CoachID = ,*/ DivisionID = 3, ConferenceID = 2
                },
                new Team {
                    TeamName = "New Jersey Devils", TeamLocation = "New Jersey", /*CoachID = ,*/ DivisionID = 3, ConferenceID = 2
                },
                new Team {
                    TeamName = "New York Islanders", TeamLocation = "New York", /*CoachID = ,*/ DivisionID = 3, ConferenceID = 2
                },
                new Team {
                    TeamName = "New York Rangers", TeamLocation = "New York", /*CoachID = ,*/ DivisionID = 3, ConferenceID = 2
                },
                new Team {
                    TeamName = "Philidelphia Flyers", TeamLocation = "Pennsylvania", /*CoachID = ,*/ DivisionID = 3, ConferenceID = 2
                },
                new Team {
                    TeamName = "Pittsburgh Penguins", TeamLocation = "Pennsylvania", /*CoachID = ,*/ DivisionID = 3, ConferenceID = 2
                },
                new Team {
                    TeamName = "Washington Capitals", TeamLocation = "Washington, D.C.", /*CoachID = ,*/ DivisionID = 3, ConferenceID = 2
                },
                new Team {
                    TeamName = "Boston Bruins", TeamLocation = "Massachusetts", /*CoachID = ,*/ DivisionID = 4, ConferenceID = 2
                },
                new Team {
                    TeamName = "Buffalo Sabres", TeamLocation = "New York", /*CoachID = ,*/ DivisionID = 4, ConferenceID = 2
                },
                new Team {
                    TeamName = "Detroit Red Wings", TeamLocation = "Michigan", /*CoachID = ,*/ DivisionID = 4, ConferenceID = 2
                },
                new Team {
                    TeamName = "Florida Panthers", TeamLocation = "Florida", /*CoachID = ,*/ DivisionID = 4, ConferenceID = 2
                },
                new Team {
                    TeamName = "Montreal Canadiens", TeamLocation = "Quebec, Canada", /*CoachID = ,*/ DivisionID = 4, ConferenceID = 2
                },
                new Team {
                    TeamName = "Ottawa Senators", TeamLocation = "Ontario, Canada", /*CoachID = ,*/ DivisionID = 4, ConferenceID = 2
                },
                new Team {
                    TeamName = "Tampa Bay Lightning", TeamLocation = "Florida", /*CoachID = ,*/ DivisionID = 4, ConferenceID = 2
                },
                new Team {
                    TeamName = "Toronto Maple Leafs", TeamLocation = "Ontario, Canada", /*CoachID = ,*/ DivisionID = 4, ConferenceID = 2
                }
            };

            foreach (Team t in teams)
            {
                context.Team.Add(t);
            }
            context.SaveChanges();


            var players = new Player[]
            {
                new Player {
                    TeamID = 1, CoachID = 1, FirstName = "Oliver", LastName = "Ekman-Larsson", Position = Position.Defenseman, DraftDate = DateTime.Parse("2018-10-26")
                },
                new Player {
                    TeamID = 1, CoachID = 1, FirstName = "Antti", LastName = "Raanta", Position = Position.Goalie, DraftDate = DateTime.Parse("2018-12-01")
                },
                new Player {
                    TeamID = 2, CoachID = 2, FirstName = "Joe", LastName = "Pavelski", Position = Position.Center, DraftDate = DateTime.Parse("2018-10-26")
                },
                new Player {
                    TeamID = 2, CoachID = 2, FirstName = "Logan", LastName = "Couture", Position = Position.Center, DraftDate = DateTime.Parse("2018-12-01")
                },
                new Player {
                    TeamID = 9, CoachID = 9, FirstName = "Jonathan", LastName = "Toews", Position = Position.Center, DraftDate = DateTime.Parse("2018-10-26")
                },
                new Player {
                    TeamID = 9, CoachID = 9, FirstName = "Brent", LastName = "Seabrook", Position = Position.Defenseman, DraftDate = DateTime.Parse("2018-12-01")
                }
            };

            foreach (Player p in players)
            {
                context.Player.Add(p);
            }
            context.SaveChanges();
        }
        public void Add(T record)
        {
            _context.Set <T>().Add(record);

            _context.SaveChanges();
        }
 public IActionResult Edit(Team team)
 {
     db.Entry(team).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Beispiel #21
0
 public ActionResult Create(Division division)
 {
     db.Divisions.Add(division);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Beispiel #22
0
 public ActionResult Create(Player newPlayer)
 {
     db.Players.Add(newPlayer);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }