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 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); } }
public void GenerateTournament() { var tName = NameBox.Text; if (NbPlayersBox.Value != null) { var tNbPlayers = NbPlayersBox.Value.Value; IRound tRound = new GroupRound(); var t = (Array)Application.Current.FindResource("TournamentTypes"); var ch = t.GetValue(0)?.ToString() ?? throw new ArgumentNullException("t.GetValue(0).ToString()"); // Hiding unused content for development version 1.0 /*var de = t.GetValue(1)?.ToString() ?? throw new ArgumentNullException("t.GetValue(1)?.ToString()"); * var mr = t.GetValue(2)?.ToString() ?? throw new ArgumentNullException("t.GetValue(2)?.ToString()")*/; // define round type if (TypeBox.SelectedItem.ToString() == ch) { tRound = new GroupRound(); } // Hiding unused content for development version 1.0 /*else if (TypeBox.SelectedItem.ToString() == de) * tRound = new DirectEliminationRound(); * else if (TypeBox.SelectedItem.ToString() == mr) tRound = new MultiRounds();*/ App.Tournament = new Tournament.Tournament { Name = tName, //FilePath = FileBox.Text + "\\" + NameBox.Text + ".json", FilePath = "", Players = new List <Player>(tNbPlayers), Round = tRound }; } }
private static void Start() { // Set title Console.Title = $"TLH Console {Version}"; // Print starting message Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("========================================="); Console.WriteLine("LAN Tournament Helper\nMade by LOxy\n{0}", Version); Console.WriteLine("=========================================\n"); Console.ResetColor(); Thread.Sleep(5000); // Create the tournament object // Get name Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("Please enter the name of the tournament...\n"); Console.ResetColor(); string tName = Console.ReadLine(); // Get number of players int tNbPlayer; while (true) { try { Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("Please enter the number of player of the tournament..."); Console.ResetColor(); tNbPlayer = Int32.Parse(Console.In.ReadLine() !); break; } catch (FormatException) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("ERROR : Your answer is not an integer."); Console.ResetColor(); throw; } } // Get player's name List <Player> tPlayers = new List <Player>(); List <string> names = new List <string>(); for (int i = 0; i < tNbPlayer; i++) { while (true) { Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("Enter the name of player " + (i + 1) + "..."); Console.ResetColor(); string input = Console.ReadLine() !; // Check if this name is empty or already in list. if (input == "" || names.Contains(input)) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("ERROR : A player name can't be twice or empty."); Console.ResetColor(); } else { tPlayers.Add(new Player(input)); names.Add(input); break; } } } // Get type of tournament Round tRound = new Round(); while (true) { try { Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("Enter the type of Tournament :\n 1) Championship format\n 2) Direct elimination tournament\n 3) Multi-rounds tournament"); Console.ResetColor(); int input = Int32.Parse(Console.ReadLine() !); if (input < 4 && input > 0) { switch (input) { case 1: tRound = new GroupRound(); break; case 2: tRound = new DirectEliminationRound(); break; case 3: tRound = new MultiRounds(); break; } break; } } catch (FormatException) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("ERROR : Your answer is not an integer"); Console.ResetColor(); throw; } } // Create and init the tournament Tournament = new Tournament.Tournament(tName, tNbPlayer, tPlayers, tRound); Tournament.Init(); // Start the program's loop _running = true; Run(); }