/// <summary> /// Will add points to a ranking of a player, score will be multiplied by MatchCategory /// </summary> /// <param name="game"> game </param> /// <param name="player"> player </param> /// <param name="cat"> match category </param> /// <param name="score"> score </param> private void AddPoints(GameType game, PlayerType player, MatchCategories cat, int score) { int realScore = 0; switch (cat) { case MatchCategories.Training: realScore = score; break; case MatchCategories.Competition: realScore = score * 2; break; case MatchCategories.Tournament: realScore = score * 3; break; default: break; } PlayerGameRankingType r = new PlayerGameRankingType(game, player, realScore); if (backend.RankingList.Contains(r)) { backend.RankingList[backend.RankingList.IndexOf(r)] = new PlayerGameRankingType(game, player, realScore + backend.RankingList[backend.RankingList.IndexOf(r)].Points); } else { backend.RankingList.Add(new PlayerGameRankingType(game, player, realScore)); } backend.SubmitRankingListChanges(); }
/// <summary> /// Creates a team match /// </summary> /// <param name="cat"> match category </param> /// <param name="game"> game </param> /// <param name="teams"> teams </param> /// <param name="scores"> scores </param> public TeamMatch(MatchCategories cat, GameType game, List <TeamType> teams, List <int> scores) { Category = cat; GameID = game; dateTime = DateTime.Now; Scores = scores; Teams = teams; }
public SoloMatch(List <PlayerType> Players, List <int> scores, MatchCategories cat, GameType game) { this.Players = Players; Scores = scores; Category = cat; dateTime = DateTime.Now; GameID = game; }
private void btnAddTeamMatch_Click(object sender, EventArgs e) { IMatchManipulations matchLogic = new MatchLogic(); ITeamManipulations teamLogic = new TeamLogic(); IGameManipulations gameLogic = new GameLogic(); try { List <TeamType> teams = new List <TeamType>(); MatchCategories cat = (MatchCategories)Enum.Parse(typeof(MatchCategories), downUpTeamCat.SelectedItem.ToString()); GameType game = gameLogic.GetGames()[downUpTeamGame.SelectedIndex]; List <int> scores = new List <int>(); string[] parts = tbTeamScores.Text.Split(','); foreach (string s in parts) { scores.Add(int.Parse(s)); } for (int i = 0; i < clTeamTeams.CheckedItems.Count; i++) { teams.Add(teamLogic.GetTeams()[clTeamTeams.Items.IndexOf(clTeamTeams.CheckedItems[i])]); } if ((teams.Count > 0) && (teams.Count == scores.Count)) { matchLogic.AddOrUpdateTeamMatch(new TeamMatch(cat, game, teams, scores)); tbTeamScores.Text = ""; } else { MessageBox.Show("Invalid scores.", "Error: Add Match", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error: Add Match", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateTree(); }
private void btnAddSoloMatch_Click(object sender, EventArgs e) { IMatchManipulations matchLogic = new MatchLogic(); IPlayerManipulations playerLogic = new PlayerLogic(); IGameManipulations gameLogic = new GameLogic(); try { List <PlayerType> players = new List <PlayerType>(); MatchCategories cat = (MatchCategories)Enum.Parse(typeof(MatchCategories), downUpSoloCat.SelectedItem.ToString()); GameType game = gameLogic.GetGames()[downUpSoloGame.SelectedIndex]; List <int> scores = new List <int>(); string[] parts = tbSoloScores.Text.Split(','); foreach (string s in parts) { scores.Add(int.Parse(s)); } for (int i = 0; i < clSoloMembers.CheckedItems.Count; i++) { players.Add(playerLogic.GetPlayers()[clSoloMembers.Items.IndexOf(clSoloMembers.CheckedItems[i])]); } if ((players.Count > 0) && (players.Count == scores.Count)) { matchLogic.AddOrUpdateSoloMatch(new SoloMatch(players, scores, cat, game)); tbSoloScores.Text = ""; } else { MessageBox.Show("Invalid scores.", "Error: Add Match", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error: Add Match", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateTree(); }
public List <MatchType> GetMatches(GameType game, ParticipantTypes soloOrTeam, MatchCategories matchCategory) { List <MatchType> filtered = new List <MatchType>(); filtered = grda.MatchList; for (int i = 0; i < grda.MatchList.Count; i++) { if (grda.MatchList[i].GameID.Equals(game) && grda.MatchList[i].Category.Equals(matchCategory)) { //solo or team? if ((grda.MatchList[i] is SoloMatch) && (soloOrTeam == ParticipantTypes.Solo)) { filtered.Add(grda.MatchList[i]); } else if ((grda.MatchList[i] is TeamMatch) && (soloOrTeam == ParticipantTypes.Team)) { filtered.Add(grda.MatchList[i]); } else if (soloOrTeam == ParticipantTypes.All) { filtered.Add(grda.MatchList[i]); } } } return(filtered); }
/// <summary> /// Use to test and make sure that expressions will evaluate on the server rather than on the client /// </summary> public async Task TestServerSideEvaluationAsync() { var queryV1 = _context.Suppliers .Include(x => x.Products) .ThenInclude(y => y.Category) .Select(z => new { z.CompanyName, z.Products } ); //var result = await queryV1.ToListAsync(); /* info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (120ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT [x].[CompanyName], [x].[SupplierID] FROM [Suppliers] AS [x] ORDER BY [x].[SupplierID] info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (60ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT [x.Products].[ProductID], [x.Products].[CategoryID], [x.Products].[Discontinued], [x.Products].[ProductName], [x.Products].[QuantityPerUnit], [x.Products].[ReorderLevel], [x.Products].[SupplierID], [x.Products].[UnitPrice], [x.Products].[UnitsInStock], [x.Products].[UnitsOnOrder], [t].[SupplierID] FROM [Products] AS [x.Products] INNER JOIN ( SELECT [x0].[SupplierID] FROM [Suppliers] AS [x0] ) AS [t] ON [x.Products].[SupplierID] = [t].[SupplierID] ORDER BY [t].[SupplierID] */ var queryV2 = _context.Suppliers .SelectMany(x => x.Products.Select(p => new { p.ProductId, p.ProductName, p.Category })); // var resultV2 = await queryV2.ToListAsync(); var queryV3 = from a in _context.Suppliers join b in _context.Products on a.SupplierId equals b.SupplierId into MatchProducts from mo in MatchProducts.DefaultIfEmpty() join c in _context.Categories on mo.CategoryId equals c.CategoryId into MatchCategories from mc in MatchCategories.DefaultIfEmpty() select new { a.SupplierId, a.CompanyName, mo.ProductId, mo.ProductName, mc.CategoryId, CategoryNameDesc = mc.CategoryName + "\n" + mc.CategoryName }; var resultV3 = await queryV3.ToListAsync(); /* info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (86ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT [a].[SupplierID], [a].[CompanyName], [b].[ProductID] AS [ProductId], [b].[ProductName], [c].[CategoryID] AS [CategoryId], [c].[CategoryName] FROM [Suppliers] AS [a] LEFT JOIN [Products] AS [b] ON [a].[SupplierID] = [b].[SupplierID] LEFT JOIN [Categories] AS [c] ON [b].[CategoryID] = [c].[CategoryID] WHERE [c].[CategoryName] = N'Seafood' */ var queryV4 = from a in _context.Suppliers join b in _context.Products on a.SupplierId equals b.SupplierId into MatchProducts from mo in MatchProducts.DefaultIfEmpty().Take(1) join c in _context.Categories on mo.CategoryId equals c.CategoryId into MatchCategories from mc in MatchCategories.DefaultIfEmpty() select new { a.SupplierId, a.CompanyName, mo.ProductId, mo.ProductName, mc.CategoryId, mc.CategoryName }; // var resultV4 = await queryV4.Where(x => x.CategoryName == "Seafood").ToListAsync(); /* info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (107ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT [a].[SupplierID] AS [SupplierId0], [a].[Address], [a].[City], [a].[CompanyName], [a].[ContactName], [a].[ContactTitle], [a].[Country], [a].[Fax], [a].[HomePage], [a].[Phone], [a].[PostalCode], [a].[Region], [b].[ProductID], [b].[CategoryID], [b].[Discontinued], [b].[ProductName], [b].[QuantityPerUnit], [b].[ReorderLevel], [b].[SupplierID], [b].[UnitPrice], [b].[UnitsInStock], [b].[UnitsOnOrder] FROM [Suppliers] AS [a] LEFT JOIN [Products] AS [b] ON [a].[SupplierID] = [b].[SupplierID] ORDER BY [SupplierId0] info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (18ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT [c].[CategoryID], [c].[CategoryName] FROM [Categories] AS [c] */ }
/// <summary> /// Returns all filtered matches /// </summary> /// <param name="game"> game </param> /// <param name="soloOrTeam"> participant type </param> /// <param name="matchCategory"> match category </param> /// <returns> filtered matches </returns> public List<MatchType> GetMatches(GameType game, ParticipantTypes soloOrTeam, MatchCategories matchCategory) { List<MatchType> matches = new List<MatchType>(); foreach (MatchType m in backend.MatchList) { if (m.GameID == game && m.Category == matchCategory) { if ((soloOrTeam == ParticipantTypes.Solo) && (m is TeamMatch)) { continue; } if ((soloOrTeam == ParticipantTypes.Team) && (m is SoloMatch)) { continue; } if (!matches.Contains(m)) { matches.Add(m); } } } return matches; }
public List <MatchType> GetMatches(GameType game, ParticipantTypes soloOrTeam, MatchCategories matchCategory) { throw new NotImplementedException(); }
public List<MatchType> GetMatches(GameType game, ParticipantTypes soloOrTeam, MatchCategories matchCategory) { throw new NotImplementedException(); }
/// <summary> /// Returns all filtered matches /// </summary> /// <param name="game"> game </param> /// <param name="soloOrTeam"> participant type </param> /// <param name="matchCategory"> match category </param> /// <returns> filtered matches </returns> public List <MatchType> GetMatches(GameType game, ParticipantTypes soloOrTeam, MatchCategories matchCategory) { List <MatchType> matches = new List <MatchType>(); foreach (MatchType m in backend.MatchList) { if (m.GameID == game && m.Category == matchCategory) { if ((soloOrTeam == ParticipantTypes.Solo) && (m is TeamMatch)) { continue; } if ((soloOrTeam == ParticipantTypes.Team) && (m is SoloMatch)) { continue; } if (!matches.Contains(m)) { matches.Add(m); } } } return(matches); }