Skip to content

Commit

Permalink
#1 Change index VM, add players VM, support filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
afuersch committed Oct 15, 2015
1 parent 983b424 commit fce876f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
29 changes: 17 additions & 12 deletions src/Wuzlstats/Controllers/PlayersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public PlayersController(Db db, AppSettings settings)
}

[Route("~/League/{league}/Players")]
public async Task<IActionResult> Index(string league, string sort)
public async Task<IActionResult> Index(string league, string sort, bool recent)
{
var leagueEntity = _db.Leagues.FirstOrDefault(x => x.Name.ToLower() == league.ToLower());
if (leagueEntity == null)
{
return RedirectToAction("Index", "Leagues");
}
ViewBag.CurrentLeague = leagueEntity.Name;
var players = await _statisticsService.FindPlayersOfLeague(leagueEntity.Id, /*_settings.DaysForStatistics*/ null);
var players = await _statisticsService.FindPlayersOfLeague(leagueEntity.Id, recent ?_settings.DaysForStatistics : default(int?));

switch (sort)
{
Expand All @@ -47,17 +47,22 @@ public async Task<IActionResult> Index(string league, string sort)
break;
}

return View(players.Select(player => new IndexViewModel
return View(new IndexViewModel
{
PlayerId = player.Id,
Name = player.Name,
Image = player.Image == null || player.Image.Length <= 0 ? EmptyAvatar.Base64 : Convert.ToBase64String(player.Image),
Wins = player.Wins,
Losses = player.Losses,
SingleGames = player.SingleGames,
TeamGames = player.TeamGames,
LastGamePlayedOn = player.LatestGame
}));
ActiveFilter = sort,
Recent = recent,
Players = players.Select(player => new PlayerViewModel
{
PlayerId = player.Id,
Name = player.Name,
Image = player.Image == null || player.Image.Length <= 0 ? EmptyAvatar.Base64 : Convert.ToBase64String(player.Image),
Wins = player.Wins,
Losses = player.Losses,
SingleGames = player.SingleGames,
TeamGames = player.TeamGames,
LastGamePlayedOn = player.LatestGame
})
});
}

}
Expand Down
13 changes: 4 additions & 9 deletions src/Wuzlstats/ViewModels/Players/IndexViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
using System;
using System.Collections.Generic;

namespace Wuzlstats.ViewModels.Players
{
public class IndexViewModel
{
public int PlayerId { get; set; }
public string Name { get; set; }
public string Image { get; set; }
public int Wins { get; set; }
public int Losses { get; set; }
public DateTime LastGamePlayedOn { get; set; }
public int SingleGames { get; set; }
public int TeamGames { get; set; }
public string ActiveFilter { get; set; }
public bool Recent { get; set; }
public IEnumerable<PlayerViewModel> Players { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/Wuzlstats/ViewModels/Players/PlayerViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace Wuzlstats.ViewModels.Players
{
public class PlayerViewModel
{
public int PlayerId { get; set; }
public string Name { get; set; }
public string Image { get; set; }
public int Wins { get; set; }
public int Losses { get; set; }
public DateTime LastGamePlayedOn { get; set; }
public int SingleGames { get; set; }
public int TeamGames { get; set; }
}
}
13 changes: 7 additions & 6 deletions src/Wuzlstats/Views/Players/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
@model IEnumerable<Wuzlstats.ViewModels.Players.IndexViewModel>
@model Wuzlstats.ViewModels.Players.IndexViewModel

<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>
<p class="help-block">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>
<li class="@(string.IsNullOrEmpty(Model.ActiveFilter) ? "active" : "")"><a href="@Url.Action("Index", "Players", new { recent = Model.Recent })">Last played</a></li>
<li class="@(Model.ActiveFilter == "best" ? "active" : "")"><a href="@Url.Action("Index", "Players", new { sort = "best", recent = Model.Recent })">Best</a></li>
<li class="@(Model.ActiveFilter == "worst" ? "active" : "")"><a href="@Url.Action("Index", "Players", new { sort = "worst", recent = Model.Recent })">Worst</a></li>
<li class="@(Model.ActiveFilter == "activity" ? "active" : "")"><a href="@Url.Action("Index", "Players", new { sort = "activity", recent = Model.Recent })">Most active</a></li>
</ul>

<table class="table table-striped ranking players">
Expand All @@ -21,7 +22,7 @@
</thead>
<tbody>
@{var rank = 1; }
@foreach (var player in Model)
@foreach (var player in Model.Players)
{
<tr>
<td>
Expand Down

0 comments on commit fce876f

Please sign in to comment.