Пример #1
0
        public TestsViewModel(PageService pageService, UserService userService, TestsRestClient testsClient, StudentsRestClient studentsClient, QuestionsRestClient questionsRestClient, StudentAnswersRestClient studentAnswersClient)
        {
            _pageService = pageService;
            _userService = userService;

            _testsClient          = testsClient;
            _studentsClient       = studentsClient;
            _questionsClient      = questionsRestClient;
            _studentAnswersClient = studentAnswersClient;

            Tests.Clear();
            Tests = new ObservableCollection <dynamic>(HttpResponseMessageConverter.GetResult <List <dynamic> >(_testsClient.GetTests()));
        }
        public AddOrEditQuestionViewModel(PageService pageService, QuestionsRestClient questionsClient)
        {
            _pageService = pageService;

            _questionsClient = questionsClient;

            if (!IsAdding)
            {
                if (QuestionId != null)
                {
                    var question = HttpResponseMessageConverter.GetResult <dynamic>(_questionsClient.GetQuestionById((int)QuestionId));

                    Name  = question.name;
                    Photo = Convert.FromBase64String(Convert.ToString(question.photo));
                }
            }
        }
        public int GetCountCorrectedAnswers()
        {
            var userId                = Convert.ToInt32(_userService.UserInformation.id);
            var studentId             = Convert.ToInt32(HttpResponseMessageConverter.GetResult <dynamic>(_studentsClient.StudentByUserId(userId)).id);
            var studentAnswers        = HttpResponseMessageConverter.GetResult <List <dynamic> >(_studentAnswersClient.GetStudentAnswers(studentId, Convert.ToInt32(TestId)));
            var countCorrectedAnswers = 0;

            foreach (var studentAnswer in studentAnswers)
            {
                if (Convert.ToBoolean(studentAnswer.answer.isCorrect))
                {
                    countCorrectedAnswers += 1;
                }
            }

            return(countCorrectedAnswers);
        }
        public AddOrEditAnswerViewModel(PageService pageService, AnswersRestClient answersClient)
        {
            _pageService = pageService;

            _answersClient = answersClient;

            if (!IsAdding)
            {
                if (AnswerId != null)
                {
                    var answer = HttpResponseMessageConverter.GetResult <dynamic>(_answersClient.GetAnswerById((int)AnswerId));


                    IsСorrect = (bool?)answer.isCorrect;
                    Name      = answer.name;
                }
            }
        }
        public void FormQuestions()
        {
            var random    = new Random();
            var questions = new ObservableCollection <dynamic>(HttpResponseMessageConverter.GetResult <List <dynamic> >(_questionsClient.GetQuestionsByTestId((int)TestId)));

            FormCounters(questions.Count);

            for (int i = 0; i < CountQuestions; i++)
            {
                while (true)
                {
                    var item = questions[random.Next(0, questions.Count)];

                    if (!Questions.Contains(item))
                    {
                        Questions.Add(item);

                        break;
                    }
                }
            }
        }
        public PassingTheTestViewModel(PageService pageService, UserService userService, TestsRestClient testsClient, AnswersRestClient answersClient, StudentsRestClient studentsClient, QuestionsRestClient questionsClient, StudentAnswersRestClient studentAnswersClient)
        {
            _pageService = pageService;
            _userService = userService;

            _testsClient          = testsClient;
            _answersClient        = answersClient;
            _studentsClient       = studentsClient;
            _questionsClient      = questionsClient;
            _studentAnswersClient = studentAnswersClient;

            if (TestId != null)
            {
                Test = HttpResponseMessageConverter.GetResult <dynamic>(_testsClient.GetTestById((int)TestId));

                InitTimer();
                FormQuestions();

                ActiveQuestion = Questions[0];

                Answers.Clear();
                Answers = new ObservableCollection <dynamic>(HttpResponseMessageConverter.GetResult <List <dynamic> >(_answersClient.GetAnswersByQuestionId(Convert.ToInt32(ActiveQuestion.id))));
            }
        }
        public DetailsOfTheStudentPassingTheTestViewModel(PageService pageService, DetailsOfTheTestRestClient detailsOfTheClient)
        {
            _pageService = pageService;

            _detailsOfTheClient = detailsOfTheClient;

            if (StudentId != null)
            {
                DetailsOfTheStudentPassingTheTest.Clear();
                DetailsOfTheStudentPassingTheTest = new ObservableCollection <dynamic>(HttpResponseMessageConverter.GetResult <List <dynamic> >(_detailsOfTheClient.GetDetailsOfTheStudentPassingTheTest(Convert.ToInt32(TestId), Convert.ToInt32(StudentId))));
            }
        }