Ejemplo n.º 1
0
        public async Task <IActionResult> RenderScoreboardAsync([FromServices] ILabExecutionService labExecutionService, int?labId, int?slotId)
        {
            if (labId == null || slotId == null)
            {
                // Show the most recently executed lab and slot as default
                var recentLabExecution = await labExecutionService.GetMostRecentLabExecutionAsync(HttpContext.RequestAborted);

                if (recentLabExecution != null)
                {
                    labId  = recentLabExecution.LabId;
                    slotId = recentLabExecution.Group?.SlotId;
                }
            }

            return(await RenderAsync(labId ?? 0, slotId ?? 0));
        }
Ejemplo n.º 2
0
    private async Task <IActionResult> RenderAsync(int?labId)
    {
        // Retrieve group ID
        var currentUser = await GetCurrentUserAsync();

        if (currentUser?.GroupId == null)
        {
            AddStatusMessage(_localizer["RenderAsync:NoGroup"], StatusMessageTypes.Error);
            return(await RenderViewAsync());
        }

        // Show group's most recent lab
        if (labId == null)
        {
            var currentLabExecution = await _labExecutionService.GetMostRecentLabExecutionAsync(currentUser.GroupId.Value, HttpContext.RequestAborted);

            if (currentLabExecution == null)
            {
                AddStatusMessage(_localizer["RenderAsync:NoActiveLab"], StatusMessageTypes.Info);
                return(await RenderViewAsync());
            }

            labId = currentLabExecution.LabId;
        }

        // Check whether user may access this lab, if it even exists
        var lab = await _labService.GetLabAsync(labId.Value, HttpContext.RequestAborted);

        if (lab == null || (!lab.Visible && !currentUser.Privileges.HasAnyPrivilege(UserPrivileges.ViewAdminScoreboard | UserPrivileges.ViewLabs)))
        {
            AddStatusMessage(_localizer["RenderAsync:LabNotFound"], StatusMessageTypes.Error);
            return(await RenderViewAsync());
        }

        // Retrieve scoreboard
        var scoreboard = await _scoreboardService.GetUserScoreboardAsync(currentUser.Id, currentUser.GroupId.Value, labId.Value, HttpContext.RequestAborted);

        if (scoreboard == null)
        {
            AddStatusMessage(_localizer["RenderAsync:EmptyScoreboard", labId], StatusMessageTypes.Error);
            return(await RenderViewAsync());
        }

        ViewData["Scoreboard"] = scoreboard;

        return(await RenderViewAsync(MenuItems.Group));
    }
Ejemplo n.º 3
0
        private async Task <IActionResult> RenderAsync(int?labId)
        {
            // Retrieve group ID
            var currentUser = await GetCurrentUserAsync();

            if (currentUser?.GroupId == null)
            {
                AddStatusMessage(_localizer["RenderAsync:NoGroup"], StatusMessageTypes.Error);
                return(await RenderViewAsync());
            }

            // Show group's most recent lab
            if (labId == null)
            {
                var currentLabExecution = await _labExecutionService.GetMostRecentLabExecutionAsync(currentUser.GroupId.Value);

                if (currentLabExecution == null)
                {
                    AddStatusMessage(_localizer["RenderAsync:NoActiveLab"], StatusMessageTypes.Info);
                    return(await RenderViewAsync());
                }

                labId = currentLabExecution.LabId;
            }

            // Retrieve scoreboard
            var scoreboard = await _scoreboardService.GetUserScoreboardAsync(currentUser.Id, currentUser.GroupId.Value, labId.Value, HttpContext.RequestAborted);

            if (scoreboard == null)
            {
                AddStatusMessage(_localizer["RenderAsync:EmptyScoreboard", labId], StatusMessageTypes.Error);
                return(await RenderViewAsync());
            }

            ViewData["Scoreboard"] = scoreboard;

            return(await RenderViewAsync(MenuItems.Group));
        }