diff --git a/src/Apps/StatCan.OrchardCore.Candev/Controllers/AdminController.cs b/src/Apps/StatCan.OrchardCore.Candev/Controllers/AdminController.cs index 856915f58..0140f1499 100644 --- a/src/Apps/StatCan.OrchardCore.Candev/Controllers/AdminController.cs +++ b/src/Apps/StatCan.OrchardCore.Candev/Controllers/AdminController.cs @@ -107,5 +107,18 @@ public async Task SelectNHackers(int n) return RedirectToAction("Index"); } + [HttpPost] + [ValidateAntiForgeryToken] + public async Task CheckIn() + { + if (!HttpContext.User.IsInRole("Administrator")) + { + return Unauthorized(); + } + + await _candevService.CheckIn(); + _notifier.Success(H["Checked-In participants have been selected."]); + return RedirectToAction("Index"); + } } } diff --git a/src/Apps/StatCan.OrchardCore.Candev/Services/CandevService.cs b/src/Apps/StatCan.OrchardCore.Candev/Services/CandevService.cs index f09876185..1d1acfd20 100644 --- a/src/Apps/StatCan.OrchardCore.Candev/Services/CandevService.cs +++ b/src/Apps/StatCan.OrchardCore.Candev/Services/CandevService.cs @@ -599,6 +599,24 @@ public async Task SelectNHackers(int n) return true; } + public async Task CheckIn() + { + var users = await _session.Query(x => x.Roles.Contains("Hacker") && !x.CheckIn).ListAsync(); + var participants = await _session.QueryIndex(x => x.Roles.Contains("Hacker") && !x.CheckIn).ListAsync(); + + foreach (var participant in participants) + { + var user = users.Where(x => x.UserId == participant.UserId).FirstOrDefault(); + if (user.HasTeam()) + { + RemoveFromTeam(user); + } + _userManager.RemoveFromRoleAsync(user, "Hacker").GetAwaiter(); + } + + return true; + } + private async void RemoveFromTeam(User user) { var team = await _session.Query(x => x.ContentItemId == user.GetTeamId() && x.ContentType == "Team" && x.Published).FirstOrDefaultAsync(); diff --git a/src/Apps/StatCan.OrchardCore.Candev/Services/ICandevService.cs b/src/Apps/StatCan.OrchardCore.Candev/Services/ICandevService.cs index 332f2169f..0b3660f50 100644 --- a/src/Apps/StatCan.OrchardCore.Candev/Services/ICandevService.cs +++ b/src/Apps/StatCan.OrchardCore.Candev/Services/ICandevService.cs @@ -28,5 +28,6 @@ public interface ICandevService Task CreateChallenge(string challengeTitle); Task CreateTopic(string topicName, string challengeId); Task SelectNHackers(int n); + Task CheckIn(); } } diff --git a/src/Apps/StatCan.OrchardCore.Candev/Views/Admin/Index.cshtml b/src/Apps/StatCan.OrchardCore.Candev/Views/Admin/Index.cshtml index 4a0eadf4d..606526e7c 100644 --- a/src/Apps/StatCan.OrchardCore.Candev/Views/Admin/Index.cshtml +++ b/src/Apps/StatCan.OrchardCore.Candev/Views/Admin/Index.cshtml @@ -34,5 +34,17 @@ + - \ No newline at end of file +