File tree Expand file tree Collapse file tree 4 files changed +45
-1
lines changed
src/Apps/StatCan.OrchardCore.Candev Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -107,5 +107,18 @@ public async Task<IActionResult> SelectNHackers(int n)
107
107
return RedirectToAction ( "Index" ) ;
108
108
}
109
109
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
+ }
110
123
}
111
124
}
Original file line number Diff line number Diff line change @@ -599,6 +599,24 @@ public async Task<bool> SelectNHackers(int n)
599
599
return true ;
600
600
}
601
601
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
+
602
620
private async void RemoveFromTeam ( User user )
603
621
{
604
622
var team = await _session . Query < ContentItem , CandevItemsIndex > ( x => x . ContentItemId == user . GetTeamId ( ) && x . ContentType == "Team" && x . Published ) . FirstOrDefaultAsync ( ) ;
Original file line number Diff line number Diff line change @@ -28,5 +28,6 @@ public interface ICandevService
28
28
Task < string > CreateChallenge ( string challengeTitle ) ;
29
29
Task < string > CreateTopic ( string topicName , string challengeId ) ;
30
30
Task < bool > SelectNHackers ( int n ) ;
31
+ Task < bool > CheckIn ( ) ;
31
32
}
32
33
}
Original file line number Diff line number Diff line change 34
34
</button >
35
35
</form >
36
36
</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 >
37
49
</div >
38
- </div >
50
+ </div >
You can’t perform that action at this time.
0 commit comments