Skip to content

Commit

Permalink
#1 Add action, model and view for simple players list.
Browse files Browse the repository at this point in the history
  • Loading branch information
afuersch committed Sep 24, 2015
1 parent d7e134b commit 6451060
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Wuzlstats/Controllers/PlayersController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Linq;
using Microsoft.AspNet.Mvc;
using Wuzlstats.Models;
using Wuzlstats.ViewModels.Players;
using System;

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

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

[Route("~/League/{league}/Players")]
public 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();

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)
}));
}
}
}
12 changes: 12 additions & 0 deletions src/Wuzlstats/ViewModels/Players/IndexViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Wuzlstats.ViewModels.Players
{
public class IndexViewModel
{
public int PlayerId { get; set; }
public string Name { get; set; }
public string Image { get; set; }
public DateTime LastGamePlayedOn { get; set; }
}
}
20 changes: 20 additions & 0 deletions src/Wuzlstats/Views/Players/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@model IEnumerable<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>

<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>

0 comments on commit 6451060

Please sign in to comment.