Exemplo n.º 1
0
        private bool CategoryIsDone(string memberID, int categoryId)
        {
            var numberOfQuestionsInCategory = Question
                                              .Include(q => q.QuizUnit)
                                              .Where(q => q.QuizUnit.CategoryId == categoryId)
                                              .Count();

            var numberOfDoneQuestionsForUser = Progress
                                               .Include(p => p.Question)
                                               .Where(p => p.MemberId == memberID)
                                               .Where(p => p.Question.QuizUnit.CategoryId == categoryId)
                                               .Count();

            return(numberOfDoneQuestionsForUser == numberOfQuestionsInCategory);
        }
Exemplo n.º 2
0
        public MembersIndexVM GetMembersIndexVMById(string id, string userName)
        {
            MembersIndexVM membersIndexVM;

            var latestProgress = Progress
                                 .Include(p => p.Question)
                                 .Include(p => p.Question.QuizUnit)
                                 .Include(p => p.Question.QuizUnit.Category)
                                 .OrderByDescending(p => p.DateCreated)
                                 .FirstOrDefault(m => m.MemberId == id);

            if (latestProgress == null)
            {
                // Användaren har inte klarat av någon fråga än:
                membersIndexVM = new MembersIndexVM
                {
                    HasPreviousProgress = false,
                    UserName            = userName,
                };
            }
            else
            {
                // Läs in tidigare progress
                string categoryTitle = latestProgress.Question.QuizUnit.Category.Title;
                string quizUnitTitle = latestProgress.Question.QuizUnit.InfoTextHeader;
                string questionTitle = latestProgress.Question.QuestionText;
                int    questionId    = latestProgress.Question.QuestionId;

                membersIndexVM = new MembersIndexVM
                {
                    HasPreviousProgress = true,
                    CategoryName        = categoryTitle,
                    QuestionText        = questionTitle,
                    QuestionID          = questionId,
                    QuizUnitName        = quizUnitTitle,
                    UserName            = userName,
                };
            }

            return(membersIndexVM);
        }