Codepoints stats page

This commit is contained in:
Michael 2017-05-02 20:59:58 -04:00
parent 7b23b2c724
commit 737a18b592
5 changed files with 75 additions and 2 deletions

View file

@ -42,5 +42,36 @@ public ActionResult Pong(int id = 1)
return View(model); return View(model);
} }
public ActionResult Codepoints(int id)
{
var db = new ApplicationDbContext();
var highscores = new List<PongHighscore>();
foreach (var user in db.Users)
{
highscores.Add(new PongHighscore
{
UserId = user.Id,
Level = user.Pong_HighestLevel,
CodepointsCashout = user.Codepoints
});
}
id = id - 1;
int pagecount = highscores.GetPageCount(10);
if (id > pagecount || id < 0)
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
var pages = highscores.OrderByDescending(x => x.CodepointsCashout).ToArray().GetItemsOnPage(id, 10);
var model = new PongStatsViewModel
{
Highscores = pages.ToList(),
CurrentPage = id,
PageCount = 10
};
return View(model);
}
} }
} }

View file

@ -8,7 +8,7 @@ namespace Project_Unite.Models
public class PongHighscore public class PongHighscore
{ {
public string UserId { get; set; } public string UserId { get; set; }
public int CodepointsCashout { get; set; } public long CodepointsCashout { get; set; }
public int Level { get; set; } public int Level { get; set; }
} }

View file

@ -586,6 +586,7 @@
<Content Include="Views\Bugs\ViewBug.cshtml" /> <Content Include="Views\Bugs\ViewBug.cshtml" />
<Content Include="Views\Bugs\PostBug.cshtml" /> <Content Include="Views\Bugs\PostBug.cshtml" />
<Content Include="Views\Stats\Pong.cshtml" /> <Content Include="Views\Stats\Pong.cshtml" />
<Content Include="Views\Stats\Codepoints.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />

View file

@ -0,0 +1,41 @@
@model Project_Unite.Models.PongStatsViewModel
@{
ViewBag.Title = "Codepoints Highscores";
}
<h2>Codepoints Stats</h2>
<p>In ShiftOS, Codepoints are your primary form of currency. You earn them by doing many actions such as playing Pong, drawing pictures in Artpad, skinning and shifting in Shifter, and more.</p>
<p>You can use them to upgrade your OS, download more apps, etc.</p>
<p>Below is a list of all users with Codepoints, starting with the top Shifters.</p>
<table class="table-condensed">
<tr>
<th>User</th>
<th>Codepoints</th>
</tr>
@foreach(var entry in Model.Highscores)
{
<tr>
<td>@Html.UserLink(entry.UserId)</td>
<td>@entry.CodepointsCashout CP</td>
</tr>
}
</table>
<ul class="pagination">
@for(int i = 1; i <= Model.PageCount; i++)
{
if (i == Model.CurrentPage - 1)
{
<li class="active">@Html.ActionLink(i.ToString(), "Codepoints", "Stats", new { id = i }, null)</li>
}
else
{
<li>@Html.ActionLink(i.ToString(), "Codepoints", "Stats", new { id = i }, null)</li>
}
}
</ul>

View file

@ -30,7 +30,7 @@
<ul class="pagination"> <ul class="pagination">
@for(int i = 1; i <= Model.PageCount; i++) @for(int i = 1; i <= Model.PageCount; i++)
{ {
if (i == Model.CurrentPage) if (i == Model.CurrentPage - 1)
{ {
<li class="active">@Html.ActionLink(i.ToString(), "Pong", "Stats", new { id = i }, null)</li> <li class="active">@Html.ActionLink(i.ToString(), "Pong", "Stats", new { id = i }, null)</li>
} }