Skip to content

Commit b853095

Browse files
committed
Add Check-In button and process
1 parent 2c40fdc commit b853095

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

src/Apps/StatCan.OrchardCore.Candev/Controllers/AdminController.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,18 @@ public async Task<IActionResult> SelectNHackers(int n)
107107
return RedirectToAction("Index");
108108
}
109109

110+
[HttpPost]
111+
[ValidateAntiForgeryToken]
112+
public async Task<IActionResult> CheckIn()
113+
{
114+
if (!HttpContext.User.IsInRole("Administrator"))
115+
{
116+
return Unauthorized();
117+
}
118+
119+
await _candevService.CheckIn();
120+
_notifier.Success(H["Checked-In participants have been selected."]);
121+
return RedirectToAction("Index");
122+
}
110123
}
111124
}

src/Apps/StatCan.OrchardCore.Candev/Services/CandevService.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,24 @@ public async Task<bool> SelectNHackers(int n)
599599
return true;
600600
}
601601

602+
public async Task<bool> CheckIn()
603+
{
604+
var users = await _session.Query<User, CandevUsersIndex>(x => x.Roles.Contains("Hacker") && !x.CheckIn).ListAsync();
605+
var participants = await _session.QueryIndex<CandevUsersIndex>(x => x.Roles.Contains("Hacker") && !x.CheckIn).ListAsync();
606+
607+
foreach (var participant in participants)
608+
{
609+
var user = users.Where(x => x.UserId == participant.UserId).FirstOrDefault();
610+
if (user.HasTeam())
611+
{
612+
RemoveFromTeam(user);
613+
}
614+
_userManager.RemoveFromRoleAsync(user, "Hacker").GetAwaiter();
615+
}
616+
617+
return true;
618+
}
619+
602620
private async void RemoveFromTeam(User user)
603621
{
604622
var team = await _session.Query<ContentItem, CandevItemsIndex>(x => x.ContentItemId == user.GetTeamId() && x.ContentType == "Team" && x.Published).FirstOrDefaultAsync();

src/Apps/StatCan.OrchardCore.Candev/Services/ICandevService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ public interface ICandevService
2828
Task<string> CreateChallenge(string challengeTitle);
2929
Task<string> CreateTopic(string topicName, string challengeId);
3030
Task<bool> SelectNHackers(int n);
31+
Task<bool> CheckIn();
3132
}
3233
}

src/Apps/StatCan.OrchardCore.Candev/Views/Admin/Index.cshtml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,17 @@
3434
</button>
3535
</form>
3636
</div>
37+
<div class="mr-1" id="CheckIn-button">
38+
<a asp-action="CheckIn" asp-controller="Admin" asp-route-area="StatCan.OrchardCore.Candev"
39+
role="button" class="btn btn-primary btn-md"
40+
data-title="@T["Check-In"]"
41+
data-message="@T["Are you sure you want to run the Check-in process? Running it after the hackathon has started can delete teams."]"
42+
data-ok="@T["Yes"]"
43+
data-cancel="@T["No"]"
44+
data-ok-class="btn-primary"
45+
itemprop="RemoveUrl UnsafeUrl">
46+
@T["Check-in"]
47+
</a>
48+
</div>
3749
</div>
38-
</div>
50+
</div>

0 commit comments

Comments
 (0)