Skip to content

Commit

Permalink
Add Check-In button and process
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroy97 committed Nov 30, 2021
1 parent 2c40fdc commit b853095
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/Apps/StatCan.OrchardCore.Candev/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,18 @@ public async Task<IActionResult> SelectNHackers(int n)
return RedirectToAction("Index");
}

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> CheckIn()
{
if (!HttpContext.User.IsInRole("Administrator"))
{
return Unauthorized();
}

await _candevService.CheckIn();
_notifier.Success(H["Checked-In participants have been selected."]);
return RedirectToAction("Index");
}
}
}
18 changes: 18 additions & 0 deletions src/Apps/StatCan.OrchardCore.Candev/Services/CandevService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,24 @@ public async Task<bool> SelectNHackers(int n)
return true;
}

public async Task<bool> CheckIn()
{
var users = await _session.Query<User, CandevUsersIndex>(x => x.Roles.Contains("Hacker") && !x.CheckIn).ListAsync();
var participants = await _session.QueryIndex<CandevUsersIndex>(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<ContentItem, CandevItemsIndex>(x => x.ContentItemId == user.GetTeamId() && x.ContentType == "Team" && x.Published).FirstOrDefaultAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public interface ICandevService
Task<string> CreateChallenge(string challengeTitle);
Task<string> CreateTopic(string topicName, string challengeId);
Task<bool> SelectNHackers(int n);
Task<bool> CheckIn();
}
}
14 changes: 13 additions & 1 deletion src/Apps/StatCan.OrchardCore.Candev/Views/Admin/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,17 @@
</button>
</form>
</div>
<div class="mr-1" id="CheckIn-button">
<a asp-action="CheckIn" asp-controller="Admin" asp-route-area="StatCan.OrchardCore.Candev"
role="button" class="btn btn-primary btn-md"
data-title="@T["Check-In"]"
data-message="@T["Are you sure you want to run the Check-in process? Running it after the hackathon has started can delete teams."]"
data-ok="@T["Yes"]"
data-cancel="@T["No"]"
data-ok-class="btn-primary"
itemprop="RemoveUrl UnsafeUrl">
@T["Check-in"]
</a>
</div>
</div>
</div>
</div>

0 comments on commit b853095

Please sign in to comment.