Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General-purpose Intern Meta #481

Merged
merged 6 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions ServerCore/Pages/Pieces/InternMeta.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@page "/{eventId}/{eventRole}/Teams/{teamId}/InternMeta/{puzzleId}"
tabascq marked this conversation as resolved.
Show resolved Hide resolved
@model ServerCore.Pages.Pieces.InternMetaModel

@{
ViewData["Title"] = "Intern Puzzleday Meta";
tabascq marked this conversation as resolved.
Show resolved Hide resolved
tabascq marked this conversation as resolved.
Show resolved Hide resolved
}

<h2>Metapuzzle Pieces Earned</h2>

<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.EarnedPieces[0].Contents)
tabascq marked this conversation as resolved.
Show resolved Hide resolved
tabascq marked this conversation as resolved.
Show resolved Hide resolved
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.EarnedPieces) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Contents)
tabascq marked this conversation as resolved.
Show resolved Hide resolved
</td>
</tr>
}
</tbody>
</table>
38 changes: 38 additions & 0 deletions ServerCore/Pages/Pieces/InternMeta.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ServerCore.DataModel;
using ServerCore.Helpers;
using ServerCore.ModelBases;

namespace ServerCore.Pages.Pieces
{
[Authorize(Policy = "PlayerIsOnTeam")]
tabascq marked this conversation as resolved.
Show resolved Hide resolved
public class InternMetaModel : EventSpecificPageModel
{
public InternMetaModel(PuzzleServerContext serverContext, UserManager<IdentityUser> userManager) : base(serverContext, userManager)
{
}

public IList<Piece> EarnedPieces { get;set; }

public async Task<IActionResult> OnGetAsync(int puzzleId)
{
if (!Event.IsInternEvent)
tabascq marked this conversation as resolved.
Show resolved Hide resolved
{
return Forbid("This page is only valid for intern events.");
}

Team team = await UserEventHelper.GetTeamForPlayer(_context, Event, LoggedInUser);
int solvedPuzzleCount = await PuzzleStateHelper.GetSparseQuery(_context, Event, null, team, null).Where(ps => ps.SolvedTime != null && ps.Puzzle.SolveValue >= 10).CountAsync();
tabascq marked this conversation as resolved.
Show resolved Hide resolved
tabascq marked this conversation as resolved.
Show resolved Hide resolved

EarnedPieces = await _context.Pieces.Where(p => p.PuzzleID == puzzleId && p.ProgressLevel <= solvedPuzzleCount).OrderBy(p => p.ProgressLevel).ToListAsync();

return Page();
}
}
}