示例#1
0
        //[Authorize(AuthenticationSchemes = AuthSchemes, Roles = "Creator")]
        public async Task <IActionResult> Stats(DateTime?date)
        {
            if (date == null)
            {
                return(BadRequest("Give a correct date format"));
            }
            var games = await gameRepo.GetGamesByDate(date);

            List <Scoreboard_DTO> gamedata = new List <Scoreboard_DTO>();

            foreach (Game game in games)
            {
                QuizClass quiz = await quizRepo.GetQuizByIdAsync(game.QuizId);

                if (quiz != null)
                {
                    User user = await userMgr.FindByIdAsync(game.UserId);

                    var questions = await quizRepo.GetQuizQuestionsAsync(game.QuizId);

                    Scoreboard_DTO vm = new Scoreboard_DTO()
                    {
                        GameId         = game.GameId,
                        QuizName       = quiz.Name,
                        UserEmail      = user.Email,
                        UserName       = user.Name,
                        correctanswers = game.CorrectAnswers,
                        maxquestions   = questions.Count(),
                        completetime   = game.TimeFinished.Value.Subtract(game.TimeStarted)
                    };
                    gamedata.Add(vm);
                }
            }
            Stats_DTO stats = new Stats_DTO();

            Stats_Mapper.ConvertTo_DTO(gamedata, ref stats);
            return(Ok(stats));
        }