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));
    }
Пример #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);

                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));
        }