public void CreateStage(Season currentSeason, DateTime startDate) { _leagueContext.Entry(currentSeason).Collection(s => s.UserSeasons).Load(); _currentSeason = currentSeason; CreateGroupsWithParticipants(); CreateSchedule(startDate); _leagueContext.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())); }
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(); }
public ActionResult Edit([Bind(Include = "PlayerID,FirstName,LastName")] Player player) { if (ModelState.IsValid) { db.Entry(player).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(player)); }
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 virtual IActionResult Profile() { int userId = User.GetId(); User currentUser = _leagueContext.Users.Find(userId); ProfileAndMatches profileAndMatches = new ProfileAndMatches { Profile = _leagueContext.Profiles.Find(currentUser.ProfileId) }; var currentUserMatches = _leagueContext.Matches .Include(m => m.FirstPlayer) .ThenInclude(fp => fp.Profile) .Include(m => m.SecondPlayer) .ThenInclude(sp => sp.Profile) .Include(m => m.Round) .Where(m => m.FirstPlayerId == userId || m.SecondPlayerId == userId); if (currentUserMatches.Any()) { profileAndMatches.Matches = currentUserMatches.ToList(); profileAndMatches.Wins = _matchesStatisticsService.GetWins(profileAndMatches.Matches, userId); profileAndMatches.Losses = _matchesStatisticsService.GetLosses(profileAndMatches.Matches, userId); profileAndMatches.Winrate = _matchesStatisticsService.GetWinrate(profileAndMatches.Wins, profileAndMatches.Losses); foreach (Match match in profileAndMatches.Matches) { if (match.Round.IsGroupRound) { GroupRound groupRound = (GroupRound)match.Round; _leagueContext.Entry(groupRound).Reference(gr => gr.Group).Load(); if (groupRound.Group.SeasonId == _leagueContext.Seasons.Last().Id) { profileAndMatches.CurrentSeasonMatches.Add(match); } } else { PlayoffsRound playoffsRound = (PlayoffsRound)match.Round; if (playoffsRound.SeasonId == _leagueContext.Seasons.Last().Id) { profileAndMatches.CurrentSeasonMatches.Add(match); } } } profileAndMatches.CurrentSeasonWins = _matchesStatisticsService.GetWins(profileAndMatches.CurrentSeasonMatches, userId); profileAndMatches.CurrentSeasonLosses = _matchesStatisticsService.GetLosses(profileAndMatches.CurrentSeasonMatches, userId); profileAndMatches.CurrentSeasonWinrate = _matchesStatisticsService.GetWinrate( profileAndMatches.CurrentSeasonWins, profileAndMatches.CurrentSeasonLosses ); } return(View(profileAndMatches)); }
public virtual IActionResult Schedule() { IList <Group> groupSchedule = new Group[0]; if (_leagueService.IsStarted) { Season currentSeason = _seasonService.Current; _leagueContext.Entry(_seasonService.Current).Collection(s => s.Groups).Query() .Include(g => g.Rounds) .ThenInclude(r => r.Matches) .ThenInclude(m => m.FirstPlayer) .ThenInclude(fp => fp.Profile) .ThenInclude(p => p.League) .Include(g => g.Rounds) .ThenInclude(r => r.Matches) .ThenInclude(m => m.SecondPlayer) .ThenInclude(sp => sp.Profile) .ThenInclude(p => p.League).Load(); groupSchedule = currentSeason.Groups.ToList(); } return(View(groupSchedule)); }
public IActionResult Edit(Team team) { db.Entry(team).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Edit(Player player) { db.Entry(player).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }