Skip to content

Commit

Permalink
#1 Modify players action, view model and view.
Browse files Browse the repository at this point in the history
  • Loading branch information
afuersch committed Oct 10, 2015
1 parent d7d8857 commit d4c2dac
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
21 changes: 13 additions & 8 deletions src/Wuzlstats/Controllers/PlayersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,47 @@
using Wuzlstats.Models;
using Wuzlstats.ViewModels.Players;
using System;
using System.Threading.Tasks;
using Wuzlstats.Services;

namespace Wuzlstats.Controllers
{
public class PlayersController : Controller
{
private readonly Db _db;
private readonly AppSettings _settings;
private readonly PlayersService _statisticsService;

public PlayersController(Db db, AppSettings settings)
{
_settings = settings;
_db = db;
_statisticsService = new PlayersService(_db);
}

[Route("~/League/{league}/Players")]
public IActionResult Index(string league)
public async Task<IActionResult> Index(string league)
{
var leagueEntity = _db.Leagues.FirstOrDefault(x => x.Name.ToLower() == league.ToLower());
if (leagueEntity == null)
{
return RedirectToAction("Index", "Leagues");
}
ViewBag.CurrentLeague = leagueEntity.Name;
var players = _db.Players.Where(x => x.LeagueId == leagueEntity.Id).Select(x => new
{
Id = x.Id,
Name = x.Name,
Image = x.Image
}).ToList();
var players = await _statisticsService.FindPlayersOfLeague(leagueEntity.Id, /*_settings.DaysForStatistics*/ null);

return View(players.Select(player => new IndexViewModel
{
PlayerId = player.Id,
Name = player.Name,
Image = player.Image == null || player.Image.Length <= 0 ? EmptyAvatar.Base64 : Convert.ToBase64String(player.Image)
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
}));
}

}
}
4 changes: 4 additions & 0 deletions src/Wuzlstats/ViewModels/Players/IndexViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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; }
}
}
60 changes: 44 additions & 16 deletions src/Wuzlstats/Views/Players/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,47 @@

<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="ranking player-ranking">
@foreach (var player in Model)
{
<li>
<a href="@Url.Action("Index", "Player", new { id = player.PlayerId })">
<img src="data:image/png;base64,@player.Image" alt="@player.Name" class="ranking-image" />
</a>
<div class="ranking-name">@player.Name</div>
<div class="ranking-score">
<span>#@player.PlayerId</span>
@*<span class="ranking-wins">3<span class="glyphicon glyphicon-thumbs-up"></span></span>
<span class="ranking-losses">0<span class="glyphicon glyphicon-thumbs-down"></span></span>*@
</div>
</li>
}
</ul>
<table class="table table-striped ranking players">
<thead>
<tr>
<th></th>
<th>Player</th>
<th>Score</th>
<th>Last game</th>
<th># 1 vs. 1</th>
<th># 2 vs. 2</th>
</tr>
</thead>
<tbody>
@{var rank = 1; }
@foreach (var player in Model)
{
<tr>
<td>
@(rank++)
</td>
<td>
<a href="@Url.Action("Index", "Player", new { id = player.PlayerId })">
<img src="data:image/png;base64,@player.Image" alt="@player.Name" class="ranking-image" />
</a>
<div class="player-name">@player.Name</div>
</td>
<td>
<div class="player-score">
<span class="ranking-wins">@player.Wins<span class="glyphicon glyphicon-thumbs-up"></span></span>
<span class="ranking-losses">@player.Losses<span class="glyphicon glyphicon-thumbs-down"></span></span>
</div>
</td>
<td>
@player.LastGamePlayedOn.ToShortDateString()
</td>
<td>
@player.SingleGames
</td>
<td>
@player.TeamGames
</td>
</tr>
}
</tbody>
</table>

0 comments on commit d4c2dac

Please sign in to comment.