-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edit admin / authors per event (#212)
* Added admin & author lists to the Users (Players) page * Can now 'add' (substitute) admins / authors * Small fixes / cleanup for adding team members * Can remove admins / authors * Added puzzle counts for authors on the Users page * Updated author puzzle counts to use ToDictionaryAsync instead of doing a separate loop (thanks Morgan!!)
- Loading branch information
Showing
6 changed files
with
353 additions
and
26 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,54 @@ | ||
@page "/{eventId}/{eventRole}/Events/AddAdminOrAuthor" | ||
@model ServerCore.Pages.Events.AddAdminOrAuthorModel | ||
|
||
@{ | ||
ViewData["Title"] = "Add admin or author"; | ||
ViewData["AdminRoute"] = "/Events/Players"; | ||
var roleString = Model.addAdmin ? "admin" : "author"; | ||
} | ||
|
||
<h2>Add @roleString</h2> | ||
|
||
<div> | ||
<a asp-page="/Events/Players">Cancel</a> | ||
</div> | ||
|
||
<h4>Select a user to make an @roleString</h4> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th> | ||
@Html.DisplayNameFor(model => model.Users[0].Name) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.Users[0].Email) | ||
</th> | ||
<th> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var item in Model.Users) | ||
{ | ||
<tr> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Name) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Email) | ||
</td> | ||
<td> | ||
@if (Model.addAdmin) | ||
{ | ||
<a asp-page-handler="AddAdmin" asp-route-userId=@item.ID>Add</a> | ||
} | ||
else | ||
{ | ||
<a asp-page-handler="AddAuthor" asp-route-userId=@item.ID>Add</a> | ||
} | ||
</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> |
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,108 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
using Microsoft.EntityFrameworkCore; | ||
using ServerCore.DataModel; | ||
using ServerCore.ModelBases; | ||
|
||
namespace ServerCore.Pages.Events | ||
{ | ||
[Authorize("IsEventAdmin")] | ||
public class AddAdminOrAuthorModel : EventSpecificPageModel | ||
{ | ||
public IList<PuzzleUser> Users { get; set; } | ||
|
||
public bool addAdmin { get; set; } | ||
|
||
public AddAdminOrAuthorModel(PuzzleServerContext serverContext, UserManager<IdentityUser> userManager) : base(serverContext, userManager) | ||
{ | ||
} | ||
|
||
public async Task<IActionResult> OnGetAsync(bool addAdmin) | ||
{ | ||
this.addAdmin = addAdmin; | ||
|
||
if (addAdmin) | ||
{ | ||
Users = await (from user in _context.PuzzleUsers | ||
where !((from eventAdmin in _context.EventAdmins | ||
where eventAdmin.Event == Event | ||
where eventAdmin.Admin == user | ||
select eventAdmin).Any()) | ||
select user).ToListAsync(); | ||
} | ||
else | ||
{ | ||
Users = await (from user in _context.PuzzleUsers | ||
where !((from eventAuthor in _context.EventAuthors | ||
where eventAuthor.Event == Event | ||
where eventAuthor.Author == user | ||
select eventAuthor).Any()) | ||
select user).ToListAsync(); | ||
} | ||
|
||
return Page(); | ||
} | ||
|
||
public async Task<IActionResult> OnGetAddAdminAsync(int userId) | ||
{ | ||
// Check that the user isn't already an admin | ||
if (await (from admin in _context.EventAdmins | ||
where admin.Admin.ID == userId && | ||
admin.Event == Event | ||
select admin).AnyAsync()) | ||
{ | ||
return NotFound("User is already an admin in this event."); | ||
} | ||
|
||
EventAdmins Admin = new EventAdmins(); | ||
|
||
PuzzleUser user = await _context.PuzzleUsers.FirstOrDefaultAsync(m => m.ID == userId); | ||
if (user == null) | ||
{ | ||
return NotFound("Could not find user with ID '" + userId + "'. Check to make sure the user hasn't been removed."); | ||
} | ||
Admin.Admin = user; | ||
|
||
Admin.Event = Event; | ||
|
||
_context.EventAdmins.Add(Admin); | ||
await _context.SaveChangesAsync(); | ||
return RedirectToPage("/Events/Players"); | ||
} | ||
|
||
public async Task<IActionResult> OnGetAddAuthorAsync(int userId) | ||
{ | ||
// Check that the user isn't already an author | ||
if (await (from author in _context.EventAuthors | ||
where author.Author.ID == userId && | ||
author.Event == Event | ||
select author).AnyAsync()) | ||
{ | ||
return NotFound("User is already an author in this event."); | ||
} | ||
|
||
EventAuthors Author = new EventAuthors(); | ||
|
||
PuzzleUser user = await _context.PuzzleUsers.FirstOrDefaultAsync(m => m.ID == userId); | ||
if (user == null) | ||
{ | ||
return NotFound("Could not find user with ID '" + userId + "'. Check to make sure the user hasn't been removed."); | ||
} | ||
Author.Author = user; | ||
|
||
Author.Event = Event; | ||
|
||
_context.EventAuthors.Add(Author); | ||
await _context.SaveChangesAsync(); | ||
return RedirectToPage("/Events/Players"); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,64 +1,154 @@ | ||
@page "/{eventId}/{eventRole}/Events/Players" | ||
@model ServerCore.Pages.Events.PlayersModel | ||
@{ | ||
ViewData["Title"] = "Players"; | ||
ViewData["Title"] = "Users"; | ||
ViewData["AdminRoute"] = "/Events/Players"; | ||
ViewData["AuthorRoute"] = "/EventSpecific/Index"; | ||
ViewData["PlayRoute"] = "/EventSpecific/Index"; | ||
} | ||
|
||
<h2>Players</h2> | ||
<h2>Users</h2> | ||
|
||
<h3>Admins</h3> | ||
<a asp-page="/Events/AddAdminOrAuthor" asp-route-addAdmin=true>Add admin</a> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th> | ||
@Html.DisplayNameFor(model => model.Admins[0].Name) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.Admins[0].Email) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.Admins[0].EmployeeAlias) | ||
</th> | ||
<th> | ||
</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var item in Model.Admins) | ||
{ | ||
<tr> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Name) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Email) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.EmployeeAlias) | ||
</td> | ||
<td> | ||
<a asp-page-handler="RemoveAdmin" asp-route-userId=@item.ID>Remove</a> | ||
</td> | ||
<td></td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
|
||
<h4>All admin e-mails</h4> | ||
|
||
<p>@Model.AdminEmails</p> | ||
|
||
<h3>Authors</h3> | ||
<a asp-page="/Events/AddAdminOrAuthor" asp-route-addAdmin=false>Add author</a> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th> | ||
Player @Html.DisplayNameFor(model => model.Players[0].Member.ID) | ||
@Html.DisplayNameFor(model => model.Authors[0].Item1.Name) | ||
</th> | ||
<th> | ||
Player @Html.DisplayNameFor(model => model.Players[0].Member.Name) | ||
@Html.DisplayNameFor(model => model.Authors[0].Item1.Email) | ||
</th> | ||
<th> | ||
Player @Html.DisplayNameFor(model => model.Players[0].Member.Email) | ||
@Html.DisplayNameFor(model => model.Authors[0].Item1.EmployeeAlias) | ||
</th> | ||
<th> | ||
Team @Html.DisplayNameFor(model => model.Players[0].Team.ID) | ||
Puzzle count | ||
</th> | ||
<th> | ||
Team @Html.DisplayNameFor(model => model.Players[0].Team.Name) | ||
</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var item in Model.Players) | ||
@foreach (var item in Model.Authors) | ||
{ | ||
<tr> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Member.ID) | ||
@Html.DisplayFor(modelItem => item.Item1.Name) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Item1.Email) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Item1.EmployeeAlias) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Item2) | ||
</td> | ||
<td> | ||
<a asp-page-handler="RemoveAuthor" asp-route-userId=@item.Item1.ID>Remove</a> | ||
</td> | ||
<td></td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
|
||
<h4>All author e-mails</h4> | ||
|
||
<p>@Model.AuthorEmails</p> | ||
|
||
<h3>Players</h3> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th> | ||
@Html.DisplayNameFor(model => model.Players[0].Member.Name) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.Players[0].Member.Email) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.Players[0].Member.EmployeeAlias) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.Players[0].Team.Name) | ||
</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var item in Model.Players) | ||
{ | ||
<tr> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Member.Name) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Member.Email) | ||
</td> | ||
<td> | ||
<a asp-page="/Teams/Details" asp-route-id="@item.Team.ID">@Html.DisplayFor(modelItem => item.Team.ID)</a> | ||
@Html.DisplayFor(modelItem => item.Member.EmployeeAlias) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Team.Name) | ||
<a asp-page="/Teams/Members" asp-route-teamId="@item.Team.ID">@Html.DisplayFor(modelItem => item.Team.Name)</a> | ||
</td> | ||
<td></td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
|
||
<h3>All player e-mails</h3> | ||
|
||
<p>@Model.Emails</p> | ||
<h4>All player e-mails</h4> | ||
|
||
<div> | ||
<a asp-page="./Index">Back to event list</a> | ||
</div> | ||
<p>@Model.PlayerEmails</p> |
Oops, something went wrong.