コード例 #1
0
ファイル: ModuleService.cs プロジェクト: LeszekR/EduBot
        // ---------------------------------------------------------------------------------------------
        public ModuleDTO GetDTOWithQuestions(edumodule module, int userId)
        {
            ModuleDTO moduleDTO = ModuleMapper.GetDTO(module);
            List <TestQuestionDTO> questionDtosOfModule = QuestionDtosForModule(module);
            List <TestCodeDTO>     codeDtosOfModule     = CodeDtosForModule(module);


            // Wersja dla NAUCZYCIELA (do edycji modułów)
            // .........................................................................
            // brak id użytkownika - pytania będą zawierać indeks prawidłowej odpowiedzi
            // - ta wersja potrzebna jest do edycji modułów
            if (userId < 0)
            {
                moduleDTO.test_questions_DTO = questionDtosOfModule;
                moduleDTO.test_codes_DTO     = codeDtosOfModule;
                return(moduleDTO);
            }


            // Wersja dla STUDENTA
            // .........................................................................
            // Jest id uzytkownika -
            // - pytania będą zawierały indeks ostatniej odpowiedzi udzielonej przez użytkownika
            // - kody będą zawierały kody utworzone przez użytkownika
            // (zamiana indeksów prawidłowych odpowiedzi na ostatnie odpowiedzi podane przez użytkownika
            // i prawidłowych wyników kodu na kody utworzone przez użytkownika).
            moduleDTO.test_questions_DTO = SetStudentAnswers(userId, questionDtosOfModule);
            moduleDTO.test_codes_DTO     = SetStudentCodes(userId, codeDtosOfModule);


            // moduł gotowy do wysłania studentowi
            return(moduleDTO);
        }
コード例 #2
0
ファイル: ModuleService.cs プロジェクト: LeszekR/EduBot
        // ---------------------------------------------------------------------------------------------
        public string FillMetaModules()
        {
            string[] stopnie = { "medium", "hard" };

            List <edumodule> modules;

            ModuleDTO[] children;

            for (int i = 0; i < 2; i++)
            {
                // pobranie wszystkich modułów na danym stopniu trudności
                modules = _moduleRepository.All().Where(m => m.difficulty == stopnie[i]).ToList();

                // wypełnienie modułu nadrzędnego treścią jego dzieci
                foreach (var module in modules)
                {
                    children = module.edumodule1
                               .ToList()
                               .Select(child => ModuleMapper.GetDTO(child))
                               .ToArray();
                    FillMetaModule(children, module);
                }
            }

            return("Automatycznie wypełniono meta moduły zawartością ich dzieci");
        }
コード例 #3
0
ファイル: ModuleService.cs プロジェクト: LeszekR/EduBot
        // PRIVATE
        // =============================================================================================
        private ModuleDTO GetDTOWitResults(ICollection <user_question> userQuestions, List <test_question> passedQuests, ICollection <user_code> userCodes, List <test_code> passedCodes, edumodule mod)
        {
            ModuleDTO dto = ModuleMapper.GetDTO(mod);
            IEnumerable <test_question> moduleQuests;
            IEnumerable <test_code>     moduleCodes;

            moduleQuests = QuestionsForModule(mod);

            // this module has no questions
            if (moduleQuests.Count() == 0)
            {
                dto.solvedQuestions = true;
            }

            // the user has not answered this module's questions yet
            else if (userQuestions.FirstOrDefault(q => moduleQuests.Contains(q.test_question)) == null)
            {
                dto.solvedQuestions = false;
            }

            // check the latest user's results with this module question test
            else
            {
                dto.solvedQuestions = moduleQuests.FirstOrDefault(q => !passedQuests.Contains(q)) == null;
            }


            // codeTasks for the module
            moduleCodes = CodesForModule(mod);

            // this module has no code test
            if (moduleCodes.Count() == 0)
            {
                dto.solvedCodes = true;
            }

            // the user has not taken this module's code test yet
            else if (userCodes.FirstOrDefault(c => moduleCodes.Contains(c.test_code)) == null)
            {
                dto.solvedCodes = false;
            }

            // check the latest user's results with this module code test
            else
            {
                dto.solvedCodes = moduleCodes.FirstOrDefault(c => !passedCodes.Contains(c)) == null;
            }

            return(dto);
        }