Skip to content

Commit

Permalink
#1 Make players sortable via querystring.
Browse files Browse the repository at this point in the history
  • Loading branch information
afuersch committed Oct 11, 2015
1 parent 1171ae2 commit 983b424
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Wuzlstats/Controllers/PlayersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public PlayersController(Db db, AppSettings settings)
}

[Route("~/League/{league}/Players")]
public async Task<IActionResult> Index(string league)
public async Task<IActionResult> Index(string league, string sort)
{
var leagueEntity = _db.Leagues.FirstOrDefault(x => x.Name.ToLower() == league.ToLower());
if (leagueEntity == null)
Expand All @@ -32,6 +32,21 @@ public async Task<IActionResult> Index(string league)
ViewBag.CurrentLeague = leagueEntity.Name;
var players = await _statisticsService.FindPlayersOfLeague(leagueEntity.Id, /*_settings.DaysForStatistics*/ null);

switch (sort)
{
case "best":
players = players.OrderByDescending(x => x.Rank);
break;
case "worst":
players = players.OrderBy(x => x.Rank);
break;
case "activity":
players = players.OrderByDescending(x => x.Wins + x.Losses);
break;
default:
break;
}

return View(players.Select(player => new IndexViewModel
{
PlayerId = player.Id,
Expand Down
6 changes: 6 additions & 0 deletions src/Wuzlstats/Views/Players/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

<p>These are all the players. Ever.<br />No one will be forgotten. Shame and fame will last till the very end of days, or at least until a database crash with no backups.</p>

<ul class="list-unstyled list-inline filter">
<li><a href="@Url.Action("Index", "Players", new { sort = "best" })">Best</a></li>
<li><a href="@Url.Action("Index", "Players", new { sort = "worst" })">Worst</a></li>
<li><a href="@Url.Action("Index", "Players", new { sort = "activity" })">Most active</a></li>
</ul>

<table class="table table-striped ranking players">
<thead>
<tr>
Expand Down

0 comments on commit 983b424

Please sign in to comment.