Skip to content

Commit

Permalink
#5 Fill remaining team view model properties.
Browse files Browse the repository at this point in the history
Resolve last played game date.
Calculate game count of team.
  • Loading branch information
Adrian Fürschuß committed Jan 21, 2017
1 parent 952f778 commit 5edda2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Wuzlstats/Services/TeamStatisticsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,24 @@ join player in _db.Players.AsNoTracking() on position.PlayerId equals player.Id
redTeam.Wins++;
blueTeam.Losses++;
}
//Resolve date of last played game
ResolveLastGamePlayedOn(redTeam, game.Date);
ResolveLastGamePlayedOn(blueTeam, game.Date);
}
}

return teams;
}


private void ResolveLastGamePlayedOn(TeamViewModel team, DateTime date)
{
if (team.LastGamePlayedOn < date)
{
team.LastGamePlayedOn = date;
}
}

public static TeamViewModel CreateTeam(PlayerViewModel p1, PlayerViewModel p2)
{
if (p1.Id <= p2.Id)
Expand Down
2 changes: 1 addition & 1 deletion src/Wuzlstats/ViewModels/Teams/TeamViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class TeamViewModel
public int Wins { get; set; }
public int Losses { get; set; }
public DateTime LastGamePlayedOn { get; set; }
public int GamesCount { get; set; }
public int GamesCount => Wins + Losses;

// ReSharper disable once PossibleLossOfFraction
public double Rank => Losses == 0 ? Wins : (Wins == 0 ? 0.1d / Losses : (double)Wins / Losses);
Expand Down

0 comments on commit 5edda2c

Please sign in to comment.