Ejemplo n.º 1
0
        // ---------------------------------------------------------------------------------------------
        private void Promotion(ref user user)
        {
            var userQuestions   = user.user_question.ToList();
            var userCodes       = user.user_code.ToList();
            var hardUserModules = user.edumodule
                                  .Select(m => {
                if (m.difficulty == "hard")
                {
                    return(m);
                }
                if (m.difficulty == "medium")
                {
                    return(m.edumodule2);
                }
                return(m.edumodule2.edumodule2);
            })
                                  .Distinct().ToList();


            // check each 'hard' module the user has worked on
            List <test_question> moduleQuestions;
            List <test_code>     moduleCodes;
            int nPassedModules = 0;

            foreach (var module in hardUserModules)
            {
                // get all questions for the module
                moduleQuestions = _moduleService.QuestionsForModule(module);

                // the user has not answered the question yet
                if (moduleQuestions.Exists(q => !userQuestions.Exists(uq => q.id == uq.question_id)))
                {
                    continue;
                }

                // the user answered incorrectly
                if (moduleQuestions.Exists(q => userQuestions.Exists(uq => uq.question_id == q.id && uq.last_result == false)))
                {
                    continue;
                }


                // get all codeTasks
                moduleCodes = _moduleService.CodesForModule(module);

                // the user has not tried this code yet
                if (moduleCodes.Exists(c => !userCodes.Exists(uc => c.id == uc.code_id)))
                {
                    continue;
                }

                // the user answered incorrectly
                if (moduleCodes.Exists(c => userCodes.Exists(uc => uc.test_code == c && uc.last_result == false)))
                {
                    continue;
                }

                // if number of incorrect answers+codes == 0 - increment nPassed 'hard' modules
                nPassedModules++;
            }


            // find the rank assiged to this number of passed 'hard' modules
            var rankStep = Int32.Parse(ConfigurationManager.AppSettings["rankStep"]);
            var newRank  = (int)(nPassedModules / rankStep);

            // assign the rank to the user
            var oldRank = user.user_game.rank;

            user.user_game.rank = newRank;
        }