Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async Task<PlayerStatistics> GetStatisticsForPlayer(int leagueId, int season, int playerId)
- {
- var playerInProtocol = await RepositoryDbContext.LineUps
- .CountAsync(s => s.Protocol.ProtocolSeason == season &&
- s.Protocol.LeagueTableId == leagueId &&
- s.PlayerId == playerId
- && (s.LineUpPlayerRole == 1 || s.LineUpPlayerRole == 2));
- var playerPlayed = await RepositoryDbContext.LineUps
- .CountAsync(s => s.Protocol.ProtocolSeason == season &&
- s.Protocol.LeagueTableId == leagueId &&
- s.PlayerId == playerId
- && (s.LineUpPlayerRole == 1));
- var playerYellowCards = await RepositoryDbContext.PlayEvents
- .Where(s => s.Protocol.ProtocolSeason == season &&
- s.Protocol.LeagueTableId == leagueId &&
- s.PlayEventTypeId == 5
- && s.Player1Id == playerId)
- .CountAsync();
- var playerRedCards = await RepositoryDbContext.PlayEvents
- .Where(s => s.Protocol.ProtocolSeason == season &&
- s.Protocol.LeagueTableId == leagueId &&
- s.PlayEventTypeId == 6
- && s.Player1Id == playerId)
- .CountAsync();
- var playerGoals = await RepositoryDbContext.PlayEvents
- .Where(s => s.Protocol.ProtocolSeason == season &&
- s.Protocol.LeagueTableId == leagueId &&
- (s.PlayEventTypeId == 1 || s.PlayEventTypeId == 3)
- && s.Player1Id == playerId)
- .CountAsync();
- var playerAssists = await RepositoryDbContext.PlayEvents
- .Where(s => s.Protocol.ProtocolSeason == season &&
- s.Protocol.LeagueTableId == leagueId &&
- (s.PlayEventTypeId == 1 || s.PlayEventTypeId == 3)
- && s.Player2Id == playerId)
- .CountAsync();
- var playerSubIn = await RepositoryDbContext.PlayEvents
- .Where(s => s.Protocol.ProtocolSeason == season &&
- s.Protocol.LeagueTableId == leagueId &&
- s.PlayEventTypeId == 7
- && s.Player1Id == playerId)
- .Select(p => new DTO.Statistics()
- {
- Type = p.PlayEventType.PlayEventTypeNameEng,
- StatisticsMinute = 90 - p.PlayEventMin,
- StatisticsProtocolId = p.ProtocolId
- })
- .ToListAsync();
- var playerSubOut = await RepositoryDbContext.PlayEvents
- .Where(s => s.Protocol.ProtocolSeason == season &&
- s.Protocol.LeagueTableId == leagueId &&
- s.PlayEventTypeId == 7
- && s.Player2Id == playerId)
- .Select(p => new DTO.Statistics()
- {
- Type = p.PlayEventType.PlayEventTypeNameEng,
- StatisticsMinute = 90 - p.PlayEventMin,
- StatisticsProtocolId = p.ProtocolId
- })
- .ToListAsync();
- var res = new PlayerStatistics()
- {
- PlayerStatisticsTimesStarting = playerPlayed,
- PlayerStatisticsTimesCameFromBench = playerSubIn,
- PlayerStatisticsTimesInProtocol = playerInProtocol,
- PlayerStatisticsYellowCards = playerYellowCards,
- PlayerStatisticsRedCards = playerRedCards,
- PlayerStatisticsGoals = playerGoals,
- PlayerStatisticsAssists = playerAssists,
- PlayerStatisticsMinutes = ((playerPlayed * 90) - (playerSubOut.Sum(s => s.StatisticsMinute))) + (playerSubIn.Sum(s => s.StatisticsMinute)),
- PlayerStatisticsSubOut = playerSubOut
- };
- return res;
- }
- public class Statistics
- {
- public string Type { get; set; }
- public int StatisticsProtocolId { get; set; }
- public int StatisticsMinute { get; set; }
- }
- public class PlayerStatistics
- {
- public int PlayerStatisticsGoals{ get; set; }
- public int PlayerStatisticsAssists{ get; set; }
- public int PlayerStatisticsYellowCards{ get; set; }
- public int PlayerStatisticsRedCards{ get; set; }
- public int PlayerStatisticsMinutes{ get; set; }
- public int PlayerStatisticsTimesInProtocol{ get; set; }
- public int PlayerStatisticsTimesStarting{ get; set; }
- public List<Statistics> PlayerStatisticsTimesCameFromBench{ get; set; }
- public List<Statistics> PlayerStatisticsSubOut { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement