Skip to content

Commit

Permalink
Merge pull request #78 from chriswblake/develop
Browse files Browse the repository at this point in the history
Release v0.20.0
  • Loading branch information
chriswblake authored Aug 5, 2023
2 parents 2837474 + ea0883c commit b469f21
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 54 deletions.
25 changes: 16 additions & 9 deletions HackathonWebApp/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,31 @@ public async Task<IActionResult> CreateRole([Required] string name)
[HttpPost]
public async Task<IActionResult> DeleteRole(string id)
{
// Find role info
ApplicationRole role = await roleManager.FindByIdAsync(id);
if (role != null)
if (role == null)
{
IdentityResult result = await roleManager.DeleteAsync(role);
if (result.Succeeded)
return RedirectToAction("Roles");
else
Errors(result);
}
else
ModelState.AddModelError("", "No role found");
return RedirectToAction("Roles");
}

// Remove role from all users
var affectedUsers = await userManager.GetUsersInRoleAsync(role.Name);
foreach (var user in affectedUsers)
await userManager.RemoveFromRoleAsync(user, role.Name);

// Delete role
IdentityResult result = await roleManager.DeleteAsync(role);
if (!result.Succeeded)
Errors(result);

return RedirectToAction("Roles");
}

// Methods - Sponsor
public ViewResult Sponsors()
{
var sponsors = this.activeEvent.Sponsors.Values.ToList();
var sponsors = this.activeEvent.Sponsors.Values.OrderBy(p=> p.DisplayPriority).ToList();
return View(sponsors);
}
public IActionResult CreateSponsor() => View();
Expand Down
5 changes: 4 additions & 1 deletion HackathonWebApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ public IActionResult Selection()
}
public IActionResult Sponsors()
{
var sponsors = this.activeEvent.Sponsors.Values.ToList();
var sponsors = this.activeEvent.Sponsors.Values
.Where(p=> p.IsVisible)
.OrderBy(p=> p.DisplayPriority)
.ToList();
return View(sponsors);
}
public IActionResult SponsorBenefits()
Expand Down
15 changes: 13 additions & 2 deletions HackathonWebApp/Controllers/ScoringController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,22 @@ await eventCollection.FindOneAndUpdateAsync(

// User Scoring Roles
[Authorize(Roles = "Admin")]
public ViewResult UserScoringRoles()
public async Task<ViewResult> UserScoringRoles()
{
ViewBag.AppUsers = this.userManager.Users.ToList();
// Get participants
ViewBag.Participants = this.activeEvent.EventApplications
.Where(p=> p.Value.ConfirmationState == EventApplication.ConfirmationStateOption.assigned)
.Select(p=> p.Value.AssociatedUser)
.ToList();

// Get staff and volunteers
ViewBag.Staff = await this.userManager.GetUsersInRoleAsync("Staff");
ViewBag.Volunteers = await this.userManager.GetUsersInRoleAsync("Volunteer");

// Get scoring roles and user assignments
ViewBag.ScoringRoles = this.activeEvent.ScoringRoles;
ViewBag.UserScoringRoles = this.activeEvent.UserScoringRoles;

return View();
}
[Authorize(Roles = "Admin")]
Expand Down
9 changes: 9 additions & 0 deletions HackathonWebApp/Models/Sponsor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public class Sponsor
[BsonElement("tier")]
public string Tier { get; set; }

[BsonElement("is_visible")]
public bool IsVisible { get; set; }

[BsonElement("display_priority")]
public int DisplayPriority { get; set; }

[BsonElement("years_consecutive_support")]
public int YearsConsecutiveSuppport { get; set; }

Expand All @@ -23,5 +29,8 @@ public class Sponsor

[BsonElement("logo")]
public string Logo { get; set; }

[BsonElement("notes")]
public string Notes { get; set; }
}
}
14 changes: 14 additions & 0 deletions HackathonWebApp/Views/Admin/CreateSponsor.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
<input asp-for="Tier" class="form-control" />
<span asp-validation-for="Tier" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="DisplayPriority" class="control-label"></label>
<input asp-for="DisplayPriority" class="form-control" />
<span asp-validation-for="DisplayPriority" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="YearsConsecutiveSuppport" class="control-label"></label>
<input asp-for="YearsConsecutiveSuppport" class="form-control" />
Expand All @@ -36,6 +41,15 @@
<input type="file" asp-for="Logo" class="form-control" />
<span asp-validation-for="Logo" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Notes" class="control-label"></label>
<input asp-for="Notes" class="form-control" />
<span asp-validation-for="Notes" class="text-danger"></span>
</div>
<div class="form-group">
Is Visible: <input asp-for="IsVisible" />
<span asp-validation-for="IsVisible" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
Expand Down
61 changes: 40 additions & 21 deletions HackathonWebApp/Views/Admin/Sponsors.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,48 @@
Layout = "_AdminLayout";
ViewBag.Title = "Sponsors";
var sponsors = Model;
var sponsorsByTier = sponsors.GroupBy(p => p.Tier);
}

<style>
table td:nth-child(1) {
width: 25%;
}
</style>

<h1 class="text-white">Sponsors</h1>
<table class="table table-sm table-bordered table-bordered text-white" style="background-color:var(--bh-dark-green-gray);">
<tr><th>Logo</th><th>Name</th><th>Tier</th><th>Years</th><th>Update</th><th>Delete</th></tr>
@foreach (Sponsor sponsor in sponsors)
{
<a asp-action="CreateSponsor" class="btn btn-secondary">Add a Sponsor</a>
@foreach (var group in sponsorsByTier)
{
var tierName = group.Key;

<h3 class="text-white">@tierName</h3>
<table class="table table-sm table-bordered table-bordered text-white" style="background-color:var(--bh-dark-green-gray);">
<tr>
<td style="text-align:center;"><img src="@String.Format("data:image/png;base64,{0}", sponsor.Logo)" style="height:100px;"/></td>
<td>@sponsor.Name</td>
<td>@sponsor.Tier</td>
<td>@sponsor.YearsConsecutiveSuppport</td>
<td><a class="btn btn-sm btn-primary" asp-action="UpdateSponsor" asp-route-id="@sponsor.Id">Update</a></td>
<td>
<form asp-action="DeleteSponsor" asp-route-id="@sponsor.Id" method="post">
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>
</td>
<th>Logo</th>
<th>Name</th>
<th>Visible</th>
<th>Priority</th>
<th>Years</th>
<th>Notes</th>
<th>Actions</th>
</tr>
}
<tr>
<td colspan="5">
<a asp-action="CreateSponsor" class="btn btn-secondary">Add a Sponsor</a>
</td>
</tr>
</table>
@foreach (Sponsor sponsor in group)
{
<tr>
<td style="text-align:center;"><img src="@String.Format("data:image/png;base64,{0}", sponsor.Logo)" style="width:100%;"/></td>
<td>@sponsor.Name</td>
<td>@sponsor.IsVisible</td>
<td>@sponsor.DisplayPriority</td>
<td>@sponsor.YearsConsecutiveSuppport</td>
<td>@sponsor.Notes</td>
<td>
<a class="btn btn-sm btn-primary" asp-action="UpdateSponsor" asp-route-id="@sponsor.Id">Update</a>
<form asp-action="DeleteSponsor" asp-route-id="@sponsor.Id" method="post" style="margin-top:5px">
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>
</td>
</tr>
}
</table>
}
14 changes: 14 additions & 0 deletions HackathonWebApp/Views/Admin/UpdateSponsor.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<input asp-for="Tier" class="form-control" />
<span asp-validation-for="Tier" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="DisplayPriority" class="control-label"></label>
<input asp-for="DisplayPriority" class="form-control" />
<span asp-validation-for="DisplayPriority" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="YearsConsecutiveSuppport" class="control-label"></label>
<input asp-for="YearsConsecutiveSuppport" class="form-control" />
Expand All @@ -32,13 +37,22 @@
<input asp-for="WebsiteUrl" class="form-control" />
<span asp-validation-for="WebsiteUrl" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Notes" class="control-label"></label>
<input asp-for="Notes" class="form-control" />
<span asp-validation-for="Notes" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Logo" class="control-label"></label>
<input type="hidden" asp-for="Logo" class="form-control" />
<img src="@String.Format("data:image/png;base64,{0}", @Model.Logo)" style="height:100px;"/>
<input type="file" id="NewLogo" name="NewLogo" class="form-control"/>
<span asp-validation-for="Logo" class="text-danger"></span>
</div>
<div class="form-group">
Is Visible: <input asp-for="IsVisible" />
<span asp-validation-for="IsVisible" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
Expand Down
40 changes: 19 additions & 21 deletions HackathonWebApp/Views/Scoring/UserScoringRoles.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@

@{
Layout = "_AdminLayout";
ViewBag.Title = "User Roles";
List<ApplicationUser> appUsers = ViewBag.AppUsers;
ViewBag.Title = "User Scoring Roles";

// Group users
var appUsersByGroup = new Dictionary<string, List<ApplicationUser>>() {
{ "Staff", ViewBag.Staff },
{ "Volunteers", ViewBag.Volunteers },
{ "Participants", ViewBag.Participants }
};

// Get scoring roles and user assignments
Dictionary<string, ScoringRole> scoringRoles = ViewBag.ScoringRoles;
Dictionary<string, string> userScoringRoles = ViewBag.UserScoringRoles;

// Group by users that have an ApplicationRole (Staff) or not (Participant)
var appUsersByGroup = appUsers.ToLookup(u=> (u.Roles.Count() > 0) ? "Staff" : "Participant");

// Count number of users in each role
Dictionary<string,int> userRoleCounts = userScoringRoles.GroupBy(p=> p.Value).ToDictionary(p=> p.Key, p=> p.Count());
}

<style>
.user-name {
font-size: large;
}
.user-subtext {
font-size: small;
}
</style>

<h1 class="text-white">@ViewBag.Title</h1>
<form asp-action="UpdateUserScoringRoles" enctype="multipart/form-data">
<button type="submit" class="btn btn-primary">Save</button>
Expand All @@ -48,25 +44,27 @@
}
</div>

@foreach (var appUsersGroup in appUsersByGroup)
@foreach (var appUsersGroup in appUsersByGroup)
{
var groupName = appUsersGroup.Key;
var appUsers = appUsersGroup.Value;
@* Show table for each group of users *@
<h3 class="text-white">@appUsersGroup.Key</h3>
<table class="table table-sm table-bordered table-bordered text-white" style="background-color:var(--bh-dark-green-gray);">
<table class="table table-sm table-bordered text-white" style="background-color:var(--bh-dark-green-gray);">
<tr>
<th>User</th>
<th>Role</th>
</tr>
@* Show Each User *@
@foreach (ApplicationUser appUser in appUsersGroup)
{
@foreach (ApplicationUser appUser in appUsers)
{
string userScoringRoleId = appUser.Id.ToString();
<tr>
@* Show User Info *@
<td>
<div class="user-name">@appUser.FirstName @appUser.LastName</div>
<div class="user-subtext">@appUser.Email</div>
<div class="user-subtext" style="font-size: xx-small">@appUser.Id</div>
<div title="@appUser.Email&#13;@appUser.Id">
@appUser.FirstName @appUser.LastName
</div>
</td>
@* Build Selector *@
<td>
Expand Down

0 comments on commit b469f21

Please sign in to comment.