Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. public async Task<PlayerStatistics> GetStatisticsForPlayer(int leagueId, int season, int playerId)
  2. {
  3.  
  4. var playerInProtocol = await RepositoryDbContext.LineUps
  5. .CountAsync(s => s.Protocol.ProtocolSeason == season &&
  6. s.Protocol.LeagueTableId == leagueId &&
  7. s.PlayerId == playerId
  8. && (s.LineUpPlayerRole == 1 || s.LineUpPlayerRole == 2));
  9.  
  10. var playerPlayed = await RepositoryDbContext.LineUps
  11. .CountAsync(s => s.Protocol.ProtocolSeason == season &&
  12. s.Protocol.LeagueTableId == leagueId &&
  13. s.PlayerId == playerId
  14. && (s.LineUpPlayerRole == 1));
  15.  
  16.  
  17. var playerYellowCards = await RepositoryDbContext.PlayEvents
  18. .Where(s => s.Protocol.ProtocolSeason == season &&
  19. s.Protocol.LeagueTableId == leagueId &&
  20. s.PlayEventTypeId == 5
  21. && s.Player1Id == playerId)
  22. .CountAsync();
  23.  
  24. var playerRedCards = await RepositoryDbContext.PlayEvents
  25. .Where(s => s.Protocol.ProtocolSeason == season &&
  26. s.Protocol.LeagueTableId == leagueId &&
  27. s.PlayEventTypeId == 6
  28. && s.Player1Id == playerId)
  29. .CountAsync();
  30.  
  31. var playerGoals = await RepositoryDbContext.PlayEvents
  32. .Where(s => s.Protocol.ProtocolSeason == season &&
  33. s.Protocol.LeagueTableId == leagueId &&
  34. (s.PlayEventTypeId == 1 || s.PlayEventTypeId == 3)
  35. && s.Player1Id == playerId)
  36. .CountAsync();
  37.  
  38. var playerAssists = await RepositoryDbContext.PlayEvents
  39. .Where(s => s.Protocol.ProtocolSeason == season &&
  40. s.Protocol.LeagueTableId == leagueId &&
  41. (s.PlayEventTypeId == 1 || s.PlayEventTypeId == 3)
  42. && s.Player2Id == playerId)
  43. .CountAsync();
  44.  
  45.  
  46. var playerSubIn = await RepositoryDbContext.PlayEvents
  47. .Where(s => s.Protocol.ProtocolSeason == season &&
  48. s.Protocol.LeagueTableId == leagueId &&
  49. s.PlayEventTypeId == 7
  50. && s.Player1Id == playerId)
  51. .Select(p => new DTO.Statistics()
  52. {
  53. Type = p.PlayEventType.PlayEventTypeNameEng,
  54. StatisticsMinute = 90 - p.PlayEventMin,
  55. StatisticsProtocolId = p.ProtocolId
  56. })
  57. .ToListAsync();
  58.  
  59. var playerSubOut = await RepositoryDbContext.PlayEvents
  60. .Where(s => s.Protocol.ProtocolSeason == season &&
  61. s.Protocol.LeagueTableId == leagueId &&
  62. s.PlayEventTypeId == 7
  63. && s.Player2Id == playerId)
  64. .Select(p => new DTO.Statistics()
  65. {
  66. Type = p.PlayEventType.PlayEventTypeNameEng,
  67. StatisticsMinute = 90 - p.PlayEventMin,
  68. StatisticsProtocolId = p.ProtocolId
  69. })
  70. .ToListAsync();
  71.  
  72.  
  73. var res = new PlayerStatistics()
  74. {
  75. PlayerStatisticsTimesStarting = playerPlayed,
  76. PlayerStatisticsTimesCameFromBench = playerSubIn,
  77. PlayerStatisticsTimesInProtocol = playerInProtocol,
  78. PlayerStatisticsYellowCards = playerYellowCards,
  79. PlayerStatisticsRedCards = playerRedCards,
  80. PlayerStatisticsGoals = playerGoals,
  81. PlayerStatisticsAssists = playerAssists,
  82. PlayerStatisticsMinutes = ((playerPlayed * 90) - (playerSubOut.Sum(s => s.StatisticsMinute))) + (playerSubIn.Sum(s => s.StatisticsMinute)),
  83. PlayerStatisticsSubOut = playerSubOut
  84. };
  85.  
  86. return res;
  87. }
  88.  
  89. public class Statistics
  90. {
  91. public string Type { get; set; }
  92. public int StatisticsProtocolId { get; set; }
  93. public int StatisticsMinute { get; set; }
  94. }
  95.  
  96. public class PlayerStatistics
  97. {
  98. public int PlayerStatisticsGoals{ get; set; }
  99. public int PlayerStatisticsAssists{ get; set; }
  100. public int PlayerStatisticsYellowCards{ get; set; }
  101. public int PlayerStatisticsRedCards{ get; set; }
  102. public int PlayerStatisticsMinutes{ get; set; }
  103.  
  104. public int PlayerStatisticsTimesInProtocol{ get; set; }
  105. public int PlayerStatisticsTimesStarting{ get; set; }
  106. public List<Statistics> PlayerStatisticsTimesCameFromBench{ get; set; }
  107. public List<Statistics> PlayerStatisticsSubOut { get; set; }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement