-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1 Add action, model and view for simple players list.
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
})); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |