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

Event-based Puzzles #47

Merged
merged 2 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
117 changes: 11 additions & 106 deletions ServerCore/Pages/Events/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,63 +13,15 @@
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Event[0].Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].UrlString)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].MaxNumberOfTeams)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].MaxTeamSize)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].MaxExternalsPerTeam)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].IsInternEvent)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].TeamRegistrationBegin)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].TeamRegistrationEnd)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].TeamNameChangeEnd)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].TeamMembershipChangeEnd)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].TeamMiscDataChangeEnd)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].TeamDeleteEnd)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].EventBegin)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].AnswerSubmissionEnd)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].AnswersAvailableBegin)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].StandingsAvailableBegin)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].StandingsOverride)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].ShowFastestSolves)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].AllowFeedback)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].UrlString)
</th>
<th>
@Html.DisplayNameFor(model => model.Event[0].IsInternEvent)
</th>
<th></th>
</tr>
</thead>
Expand All @@ -82,61 +34,14 @@
<td>
@Html.DisplayFor(modelItem => item.UrlString)
</td>
<td>
@Html.DisplayFor(modelItem => item.MaxNumberOfTeams)
</td>
<td>
@Html.DisplayFor(modelItem => item.MaxTeamSize)
</td>
<td>
@Html.DisplayFor(modelItem => item.MaxExternalsPerTeam)
</td>
<td>
@Html.DisplayFor(modelItem => item.IsInternEvent)
</td>
<td>
@Html.DisplayFor(modelItem => item.TeamRegistrationBegin)
</td>
<td>
@Html.DisplayFor(modelItem => item.TeamRegistrationEnd)
</td>
<td>
@Html.DisplayFor(modelItem => item.TeamNameChangeEnd)
</td>
<td>
@Html.DisplayFor(modelItem => item.TeamMembershipChangeEnd)
</td>
<td>
@Html.DisplayFor(modelItem => item.TeamMiscDataChangeEnd)
</td>
<td>
@Html.DisplayFor(modelItem => item.TeamDeleteEnd)
</td>
<td>
@Html.DisplayFor(modelItem => item.EventBegin)
</td>
<td>
@Html.DisplayFor(modelItem => item.AnswerSubmissionEnd)
</td>
<td>
@Html.DisplayFor(modelItem => item.AnswersAvailableBegin)
</td>
<td>
@Html.DisplayFor(modelItem => item.StandingsAvailableBegin)
</td>
<td>
@Html.DisplayFor(modelItem => item.StandingsOverride)
</td>
<td>
@Html.DisplayFor(modelItem => item.ShowFastestSolves)
</td>
<td>
@Html.DisplayFor(modelItem => item.AllowFeedback)
</td>
<td>
<a asp-page="./Edit" asp-route-id="@item.ID">Edit</a> |
<a asp-page="./Details" asp-route-id="@item.ID">Details</a> |
<a asp-page="./Delete" asp-route-id="@item.ID">Delete</a>
<a asp-page="./Delete" asp-route-id="@item.ID">Delete</a> |
<a asp-page="/Puzzles/Index" asp-route-eventid="@item.ID">Puzzles</a>
</td>
</tr>
}
Expand Down
2 changes: 1 addition & 1 deletion ServerCore/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<div class="col-md-3">
<h2>Guide to Microsoft Puzzle Events</h2>
<ul>
<li><a href="/puzzles">CLICK HERE TO CHECK YOUR DATABASE SETUP</a></li>
<li><a href="/events">CLICK HERE TO CHECK YOUR DATABASE SETUP</a></li>
<li><a href="https://aka.ms/puzzleday">Intern? Click Here</a></li>
<li><a href="https://aka.ms/nipd">Non-Intern Beginner? Click Here</a></li>
<li><a href="https://aka.ms/puzzlehunt">Advanced Solver? Click Here</a></li>
Expand Down
7 changes: 5 additions & 2 deletions ServerCore/Pages/Puzzles/Create.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using ServerCore.DataModel;
using ServerCore.Models;

Expand All @@ -27,17 +28,19 @@ public IActionResult OnGet()
[BindProperty]
public Puzzle Puzzle { get; set; }

public async Task<IActionResult> OnPostAsync()
public async Task<IActionResult> OnPostAsync(int eventid)
{
if (!ModelState.IsValid)
{
return Page();
}

Puzzle.Event = await _context.Event.SingleOrDefaultAsync(m => m.ID == eventid);

_context.Puzzle.Add(Puzzle);
await _context.SaveChangesAsync();

return RedirectToPage("./Index");
return RedirectToPage("./Index", new { eventid = eventid });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @asyasky, take a look at how we should be doing this (but no need to block on this)

}
}
}
2 changes: 1 addition & 1 deletion ServerCore/Pages/Puzzles/Delete.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@
<form method="post">
<input type="hidden" asp-for="Puzzle.ID" />
<input type="submit" value="Delete" class="btn btn-default" /> |
<a asp-page="./Index">Back to List</a>
<a asp-page="./Index" asp-route-eventid="@Model.Puzzle.Event?.ID">Back to List</a>
</form>
</div>
6 changes: 3 additions & 3 deletions ServerCore/Pages/Puzzles/Delete.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<IActionResult> OnGetAsync(int? id)
return NotFound();
}

Puzzle = await _context.Puzzle.SingleOrDefaultAsync(m => m.ID == id);
Puzzle = await _context.Puzzle.Where(m => m.ID == id).Include(p => p.Event).FirstOrDefaultAsync();

if (Puzzle == null)
{
Expand All @@ -45,15 +45,15 @@ public async Task<IActionResult> OnPostAsync(int? id)
return NotFound();
}

Puzzle = await _context.Puzzle.FindAsync(id);
Puzzle = await _context.Puzzle.Where(m => m.ID == id).Include(p => p.Event).FirstOrDefaultAsync();

if (Puzzle != null)
{
_context.Puzzle.Remove(Puzzle);
await _context.SaveChangesAsync();
}

return RedirectToPage("./Index");
return RedirectToPage("./Index", new { eventid = Puzzle.Event?.ID });
}
}
}
2 changes: 1 addition & 1 deletion ServerCore/Pages/Puzzles/Details.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@
</div>
<div>
<a asp-page="./Edit" asp-route-id="@Model.Puzzle.ID">Edit</a> |
<a asp-page="./Index">Back to List</a>
<a asp-page="./Index" asp-route-eventid="@Model.Puzzle.Event?.ID">Back to List</a>
</div>
2 changes: 1 addition & 1 deletion ServerCore/Pages/Puzzles/Details.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task<IActionResult> OnGetAsync(int? id)
return NotFound();
}

Puzzle = await _context.Puzzle.SingleOrDefaultAsync(m => m.ID == id);
Puzzle = await _context.Puzzle.Where(m => m.ID == id).Include(p => p.Event).FirstOrDefaultAsync();

if (Puzzle == null)
{
Expand Down
2 changes: 1 addition & 1 deletion ServerCore/Pages/Puzzles/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</div>

<div>
<a asp-page="./Index">Back to List</a>
<a asp-page="./Index" asp-route-eventid="@Model.Puzzle.Event?.ID">Back to List</a>
</div>

@section Scripts {
Expand Down
4 changes: 2 additions & 2 deletions ServerCore/Pages/Puzzles/Edit.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<IActionResult> OnGetAsync(int? id)
return NotFound();
}

Puzzle = await _context.Puzzle.SingleOrDefaultAsync(m => m.ID == id);
Puzzle = await _context.Puzzle.Where(m => m.ID == id).Include(p => p.Event).FirstOrDefaultAsync();

if (Puzzle == null)
{
Expand Down Expand Up @@ -64,7 +64,7 @@ public async Task<IActionResult> OnPostAsync()
}
}

return RedirectToPage("./Index");
return RedirectToPage("./Index", new { eventid = Puzzle.Event?.ID });
}

private bool PuzzleExists(int id)
Expand Down
2 changes: 1 addition & 1 deletion ServerCore/Pages/Puzzles/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h2>Index</h2>

<p>
<a asp-page="Create">Create New</a>
<a asp-page="Create" asp-route-eventid="@Model.EventId">Create New</a>
</p>
<table class="table">
<thead>
Expand Down
16 changes: 13 additions & 3 deletions ServerCore/Pages/Puzzles/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ public IndexModel(ServerCore.Models.PuzzleServerContext context)
_context = context;
}

public IList<Puzzle> Puzzle { get;set; }
public IList<Puzzle> Puzzle { get; set; }

public async Task OnGetAsync()
public int? EventId { get; set; }

public async Task OnGetAsync(int? eventid)
{
Puzzle = await _context.Puzzle.ToListAsync();
if (eventid != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please file an issue tracking removing the null tolerance since we don't want people accidentally wandering into all puzzles in all events

{
Puzzle = await _context.Puzzle.Where((p) => p.Event != null && p.Event.ID == eventid).ToListAsync();
EventId = eventid;
}
else
{
Puzzle = await _context.Puzzle.ToListAsync();
}
}
}
}