public async Task <IEnumerable <MatchChampionshipViewModel> > GetAll() { var result = await _matchChampionshipRepository.GetAll(); return(result.Select(_mapper.Map <MatchChampionshipViewModel>)); }
private async Task <List <StandingsViewModel> > GetStandingsBySubscriptions(List <Subscription> subscriptionList) { List <StandingsViewModel> standingsList = new List <StandingsViewModel>(); int points, played, won, drawn, lost, goalsFor, goalsAgainst, goalsDifference, percentage; var result = await _matchChampionshipRepository.GetAll(); foreach (var item in subscriptionList) { points = 0; played = 0; won = 0; drawn = 0; lost = 0; goalsFor = 0; goalsAgainst = 0; goalsDifference = 0; percentage = 0; List <MatchChampionship> _matchChampionshipList = result.Where(p => p.Calculate == true && (p.HomeSubscriptionId == item.Id || p.GuestSubscriptionId == item.Id)).ToList(); foreach (var item2 in _matchChampionshipList) { played += 1; if (item.Id == item2.Id) { if (item2.HomePoints > item2.GuestPoints) { points += 3; won += 1; goalsFor += item2.HomePoints; goalsAgainst += item2.GuestPoints; } else if (item2.HomePoints < item2.GuestPoints) { lost += 1; goalsFor += item2.HomePoints; goalsAgainst += item2.GuestPoints; } else if (item2.HomePoints == item2.GuestPoints) { points += 1; drawn += 1; goalsFor += item2.HomePoints; goalsAgainst += item2.GuestPoints; } } else { if (item2.HomePoints > item2.GuestPoints) { lost += 1; goalsFor += item2.GuestPoints; goalsAgainst += item2.HomePoints; } else if (item2.HomePoints < item2.GuestPoints) { points += 3; won += 1; goalsFor += item2.GuestPoints; goalsAgainst += item2.HomePoints; } else if (item2.HomePoints == item2.GuestPoints) { points += 1; drawn += 1; goalsFor += item2.GuestPoints; goalsAgainst += item2.HomePoints; } } } goalsDifference = goalsFor - goalsAgainst; if (points != 0) { percentage = (points * 100) / (played * 3); } StandingsViewModel standings = new StandingsViewModel { Name = item.Team.Name, Played = played, Points = points, Won = won, Drawn = drawn, Lost = lost, GoalsFor = goalsFor, GoalsAgainst = goalsAgainst, GoalsDifference = goalsDifference, Percentage = percentage }; standingsList.Add(standings); } return(standingsList.OrderByDescending(p => p.Points).ThenByDescending(p => p.Won).ThenByDescending(p => p.GoalsDifference).ThenByDescending(p => p.GoalsFor).ToList());; }