示例#1
0
        internal AdminResultatVM[] GetAdminResultatVM(UserManager <IdentityUser> userManager)
        {
            List <AdminResultatVM> adminResultatList = new List <AdminResultatVM>();

            var totalNumberOfQuestions = Question.Count();



            var listOfMember = userManager.Users.Select(u => new { u.UserName, u.Id });


            foreach (var member in listOfMember)
            {
                double q = Progress
                           .Where(p => p.MemberId == member.Id)
                           .Count();

                adminResultatList.Add(new AdminResultatVM
                {
                    Name = member.UserName,
                    ProgressPercentage = Math.Round(100.0 * q / totalNumberOfQuestions),
                });
            }

            return(adminResultatList.ToArray());
        }
示例#2
0
        /// <summary>
        /// </summary>
        /// <param name="id">The member ID of the current user</param>
        /// <returns>The next question of the Quiz unit. If there are no more questions in this quiz unit, it returns NULL.</returns>
        private Question GetNextQuestionByMemberId(string id)
        {
            // hämta användarens senaste Progress för att få fram QuestionId
            var latestDate = Progress
                             .Where(p => p.MemberId == id)
                             .Max(p => p.DateCreated);

            var latestQuestion = Progress
                                 .Where(p => p.MemberId == id)
                                 .SingleOrDefault(p => p.DateCreated.ToString() == latestDate.ToString())
                                 .Question;

            // hämta Det quiz-unitet
            var latestQuizUnit = latestQuestion.QuizUnit;

            // Ta fram nästa fråga i QuizUnitet
            var currentQuestionOrder = latestQuestion.Order;
            var que = Question
                      .Where(q => q.QuizUnit.QuizUnitId == latestQuizUnit.QuizUnitId)
                      .Where(q => q.Order > latestQuestion.Order)
                      .OrderBy(q => q.Order)
                      .FirstOrDefault();

            // returnerar frågan om någon hittades, annars returneras null.
            if (que != null)
            {
                return(que);
            }
            else
            {
                return(null);
            }
        }
示例#3
0
        internal void ResetAllProgressForMember(string memberId)
        {
            var q = Progress
                    .Where(p => p.MemberId == memberId);

            foreach (var item in q)
            {
                Progress.Remove(item);
            }
            SaveChanges();
        }
示例#4
0
        internal void ResetCategoryForMember(int categoryId, string memberId)
        {
            var q = Progress
                    .Where(p => p.Question.QuizUnit.CategoryId == categoryId)
                    .Where(p => p.MemberId == memberId);

            foreach (var item in q)
            {
                Progress.Remove(item);
            }
            SaveChanges();
        }
示例#5
0
        public ProgressVM GetProgressVM(string memberId)
        {
            ProgressVM model = new ProgressVM
            {
                DoneQuestions = Progress
                                .Where(p => p.MemberId == memberId)
                                .Count(),

                TotalAmountOfQuestion = Question.Count(),
            };

            return(model);
        }
示例#6
0
        private double GetCategoryProgress(int categoryId, string memberId)
        {
            double numberOfQuestionsInCategory = Question
                                                 .Where(q => q.QuizUnit.CategoryId == categoryId)
                                                 .Include(q => q.QuizUnit)
                                                 .Count();

            double doneQuestionsInCategory = Progress
                                             //.Where(p => p.Question.QuizUnitId == QuizUnitId)
                                             .Where(p => p.Question.QuizUnit.CategoryId == categoryId)
                                             .Where(p => p.MemberId == memberId)
                                             .Include(p => p.Question)
                                             //.ThenInclude(q => q.QuizUnit)
                                             .Count();

            return(Math.Round(100.0 * doneQuestionsInCategory / numberOfQuestionsInCategory));
        }
示例#7
0
        private QuizUnit GetQuizUnit(int categoryId, string memberId)
        {
            // Hämta alla frågor i kategorin som användaren har klarat av
            var doneQuestionsInCategory = Progress
                                          .Where(p => p.MemberId == memberId)
                                          .Where(p => p.Question.QuizUnit.CategoryId == categoryId)
                                          .Select(p => p.Question)
                                          .Include(p => p.QuizUnit)
                                          .ToArray();

            var numberOfQuestionsInCategory = Question
                                              .Where(q => q.QuizUnit.CategoryId == categoryId)
                                              .Count();

            if (doneQuestionsInCategory.Length == 0)
            {
                return(GetFirstQuizUnitInCategory(categoryId));
            }
            else if (doneQuestionsInCategory.Length >= numberOfQuestionsInCategory)
            {
                // Alla frågor i kategorin är avklarade, navigera till nästa
                var possibleComingCategories = Category
                                               .Where(c => c.Order > Category.Single(d => d.CategoryId == categoryId).Order);

                if (possibleComingCategories.Count() == 0)
                {
                    return(null);
                }
                else
                {
                    var nextCategoryId = possibleComingCategories
                                         .OrderBy(c => c.Order)
                                         .First()
                                         .CategoryId;

                    return(GetQuizUnit(nextCategoryId, memberId));
                }
            }
            else
            {
                // Hämta högsta ordern på ett avklarat quizunit i current category
                int topDoneQuizUnitOrder = doneQuestionsInCategory
                                           .Max(q => q.QuizUnit.Order);

                // Hämta alla quizunits med högre order.
                var nextQuizUnits = QuizUnit
                                    .Where(q => q.CategoryId == categoryId)
                                    .Where(q => q.Order > topDoneQuizUnitOrder);

                if (nextQuizUnits.Count() > 0)
                {
                    var nextQuizUnit = nextQuizUnits
                                       .OrderBy(q => q.Order)
                                       .Include(q => q.Category)
                                       .First();

                    return(nextQuizUnit);
                }

                return(GetFirstQuizUnitInCategory(categoryId));
            }
        }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="QuizUnitId"></param>
        /// <param name="memberId"></param>
        /// <returns>Returns null if there are no more questions in this quis-unit</returns>
        public QuizQuestionVM GetNextQuestion(int QuizUnitId, string memberId)
        {
            // Todo - Se till att den behandlar first, last och middle elements
            var doneQuestionsInQuizUnitForMember = Progress
                                                   .Where(p => p.MemberId == memberId)
                                                   .Where(p => p.Question.QuizUnitId == QuizUnitId);

            Question lastDoneQuestionInQuizUnit;

            if (doneQuestionsInQuizUnitForMember.Count() > 0)
            {
                // Användaren har avklarade frågor sedan innan i det här quizunitet
                lastDoneQuestionInQuizUnit = doneQuestionsInQuizUnitForMember
                                             .Include(p => p.Question)
                                             .OrderBy(p => p.Question.Order)
                                             .Select(p => p.Question)
                                             .Include(q => q.Answer)
                                             .Last();
            }
            else
            {
                // Användaren har inga avklarade frågor i detta quizunit
                lastDoneQuestionInQuizUnit = null;
            }

            QuizQuestionVM quizQuestionVM;

            if (lastDoneQuestionInQuizUnit == null)
            {
                // Ta första frågan i QuizUnitet
                var firstQuestionOfCurrentQuizUnit = Question
                                                     .Where(q => q.QuizUnitId == QuizUnitId)
                                                     .OrderBy(q => q.Order)
                                                     .Include(q => q.Answer)
                                                     .First();

                quizQuestionVM = new QuizQuestionVM
                {
                    QuestionText   = firstQuestionOfCurrentQuizUnit.QuestionText,
                    Answers        = firstQuestionOfCurrentQuizUnit.Answer.ToArray(),
                    QuestionId     = firstQuestionOfCurrentQuizUnit.QuestionId,
                    QuizUnitHeader = QuizUnit.SingleOrDefault(q => q.QuizUnitId == QuizUnitId).InfoTextHeader,
                    CategoryTitle  = QuizUnit.Include(q => q.Category).SingleOrDefault(q => q.QuizUnitId == QuizUnitId).Category.Title,
                };
            }
            else
            {
                // Leta upp de frågorna som har högre order

                var QuestionsOfHigherOrder = Question
                                             .Where(q => q.QuizUnitId == QuizUnitId)
                                             .Where(q => q.Order > lastDoneQuestionInQuizUnit.Order)
                                             .Include(q => q.Answer);

                if (QuestionsOfHigherOrder.Count() == 0)
                {
                    // Det finns inte fler frågor i det här Quiz-unitet
                    return(null);
                }
                else
                {
                    var porque = QuestionsOfHigherOrder
                                 .OrderBy(q => q.Order)
                                 .First();

                    quizQuestionVM = new QuizQuestionVM
                    {
                        QuestionText   = porque.QuestionText,
                        Answers        = porque.Answer.ToArray(),
                        QuestionId     = porque.QuestionId,
                        QuizUnitHeader = QuizUnit.SingleOrDefault(q => q.QuizUnitId == QuizUnitId).InfoTextHeader,
                        CategoryTitle  = QuizUnit.Include(q => q.Category).SingleOrDefault(q => q.QuizUnitId == QuizUnitId).Category.Title,
                    };
                }
            }

            var categoryId = QuizUnit
                             .SingleOrDefault(q => q.QuizUnitId == QuizUnitId)
                             .CategoryId;

            //double numberOfQuestionsInCategory = Question
            //    .Where(q => q.QuizUnit.CategoryId == categoryId)
            //    .Include(q => q.QuizUnit)
            //    .Count();

            //double doneQuestionsInCategory = Progress
            //    //.Where(p => p.Question.QuizUnitId == QuizUnitId)
            //    .Where(p => p.Question.QuizUnit.CategoryId == categoryId)
            //    .Where(p => p.MemberId == memberId)
            //    .Include(p => p.Question)
            //    //.ThenInclude(q => q.QuizUnit)
            //    .Count();

            //quizQuestionVM.CategoryProgress = Math.Round(100.0 * doneQuestionsInCategory / numberOfQuestionsInCategory);

            quizQuestionVM.CategoryProgress = GetCategoryProgress((int)categoryId, memberId);

            return(quizQuestionVM);
        }