public void QuestionChanged()
        {
            var userId        = Convert.ToInt32(_userService.UserInformation.id);
            var studentId     = Convert.ToInt32(HttpResponseMessageConverter.GetResult <dynamic>(_studentsClient.StudentByUserId(userId)).id);
            var studentAnswer = HttpResponseMessageConverter.GetResult <dynamic>(_studentAnswersClient.GetStudentAnswerByQuestionId(studentId, Convert.ToInt32(ActiveQuestion.id)));

            if (SelectedAnswer != null)
            {
                if (studentAnswer == null)
                {
                    _studentAnswersClient.AddStudentAnswer(studentId, Convert.ToInt32(SelectedAnswer));
                }
                else
                {
                    _studentAnswersClient.RemoveStudentAnswer(studentId, Convert.ToInt32(studentAnswer.answerId));
                    _studentAnswersClient.AddStudentAnswer(studentId, Convert.ToInt32(SelectedAnswer));
                }
            }

            ActiveQuestion = Questions[NumberActiveQuestion - 1];
            Answers        = new ObservableCollection <dynamic>(HttpResponseMessageConverter.GetResult <List <dynamic> >(_answersClient.GetAnswersByQuestionId(Convert.ToInt32(ActiveQuestion.id))));

            studentAnswer = HttpResponseMessageConverter.GetResult <dynamic>(_studentAnswersClient.GetStudentAnswerByQuestionId(studentId, Convert.ToInt32(ActiveQuestion.id)));

            SelectedAnswer = null;
            SelectedAnswer = (studentAnswer != null ? ((object)(studentAnswer.answer.id)) : null);
        }
        public AddOrEditTestViewModel(PageService pageService, TestsRestClient testsClient)
        {
            _pageService = pageService;

            _testsClient = testsClient;

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

                    Duration = test.duration;
                    MaximumNumberOfQuestions = test.maximumNumberOfQuestions;

                    Name        = test.name;
                    Description = test.description;

                    StartDate      = test.startDate;
                    StartTime      = test.startDate;
                    ExpirationDate = test.expirationDate;
                    ExpirationTime = test.expirationDate;
                }
            }
        }
Exemplo n.º 3
0
        public async Task<ServerResponse> UploadGarbageData(MemoryStream garbageData)
        {
            using (var client = new HttpClient())
            {
                InitializeClient(client);

                var response = await client.PostAsJsonAsync(string.Format("api/messenger/message/uploadgarbagedata"), garbageData);

                return HttpResponseMessageConverter.ConvertToServerResponse(response);
            }
        }
Exemplo n.º 4
0
        public RegistrationViewModel(PageService pageService, RolesRestClient rolesClient, GroupsRestClient groupsClient, AccountsRestClient accountsClient, StudentsRestClient studentsClient)
        {
            _pageService = pageService;

            _rolesClient    = rolesClient;
            _groupsClient   = groupsClient;
            _accountsClient = accountsClient;
            _studentsClient = studentsClient;

            Groups = HttpResponseMessageConverter.GetResult <List <dynamic> >(_groupsClient.GetGroups());
        }
Exemplo n.º 5
0
        public async Task<ServerResponse> CreateMessage(Message message)
        {
            using (var client = new HttpClient())
            {
                InitializeClient(client);

                var response = await client.PostAsJsonAsync("api/messenger/message", message);

                return HttpResponseMessageConverter.ConvertToServerResponse(response);
            }
        }
Exemplo n.º 6
0
        public async Task<ServerResponse<Message>> GetMessage(int id)
        {
            using (var client = new HttpClient())
            {
                InitializeClient(client);

                var response = await client.GetAsync(string.Format("api/messenger/message/{0}", id));

                return await HttpResponseMessageConverter<Message>.ConvertToServerResponse(response);
            }
        }
Exemplo n.º 7
0
        public async Task<ServerResponse<List<Message>>> GetAllMessages()
        {
            using (var client = new HttpClient())
            {
                InitializeClient(client);

                var response = await client.GetAsync("api/messenger/message");
                
                return await HttpResponseMessageConverter<List<Message>>.ConvertToServerResponse(response);
            }
        }
Exemplo n.º 8
0
        public async Task<ServerResponse> DeleteAllMessages()
        {
            using (var client = new HttpClient())
            {
                InitializeClient(client);

                var response = await client.DeleteAsync("api/messenger/message");

                return HttpResponseMessageConverter.ConvertToServerResponse(response);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of a <see cref="ResponseContentHandler"/> with the
        /// given <paramref name="responseContentParameter"/> and <paramref name="formatters"/>.
        /// </summary>
        /// <param name="responseContentParameter">The <see cref="HttpParameter"/> for the content of the response.</param>
        /// <param name="formatters">The collection of <see cref="MediaTypeFormatter"/> instances to use for deserializing the response content.</param>
        public ResponseContentHandler(HttpParameter responseContentParameter, IEnumerable<MediaTypeFormatter> formatters)
        {
            if (formatters == null)
            {
                throw Fx.Exception.ArgumentNull("formatters");
            }

            Type paramType = responseContentParameter == null ?
                TypeHelper.VoidType :
                responseContentParameter.Type;

            if (paramType == TypeHelper.VoidType)
            {
                this.responseMessageConverter = voidHttpResponseMessageConverter;
                this.outputParameter = HttpParameter.ResponseMessage;
            }
            else
            {
                paramType = HttpTypeHelper.GetHttpResponseOrContentInnerTypeOrNull(paramType) ?? paramType;

                if (HttpTypeHelper.IsHttpRequest(paramType))
                {
                    throw Fx.Exception.AsError(
                        new InvalidOperationException(
                            SR.InvalidParameterForContentHandler(
                                HttpParameter.HttpParameterType.Name,
                                responseContentParameter.Name,
                                responseContentParameter.Type.Name,
                                responseContentHandlerType.Name)));
                }

                Type outputParameterType = HttpTypeHelper.IsHttp(paramType) ? paramType : HttpTypeHelper.MakeHttpResponseMessageOf(paramType);
                this.outputParameter = new HttpParameter(responseContentParameter.Name, outputParameterType);

                this.inputParameter = responseContentParameter;

                if (HttpTypeHelper.IsHttpResponse(paramType))
                {
                    this.responseMessageConverter = simpleHttpResponseMessageConverter;
                }
                else if (HttpTypeHelper.IsHttpContent(paramType))
                {
                    this.responseMessageConverter = httpContentMessageConverter;
                }
                else
                {
                    Type closedConverterType = httpResponseMessageConverterGenericType.MakeGenericType(new Type[] { paramType });
                    ConstructorInfo constructor = closedConverterType.GetConstructor(Type.EmptyTypes);
                    this.responseMessageConverter = constructor.Invoke(null) as HttpResponseMessageConverter;
                }
            }

            this.Formatters = new MediaTypeFormatterCollection(formatters);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of a <see cref="ResponseContentHandler"/> with the
        /// given <paramref name="responseContentParameter"/> and <paramref name="formatters"/>.
        /// </summary>
        /// <param name="responseContentParameter">The <see cref="HttpParameter"/> for the content of the response.</param>
        /// <param name="formatters">The collection of <see cref="MediaTypeFormatter"/> instances to use for deserializing the response content.</param>
        public ResponseContentHandler(HttpParameter responseContentParameter, IEnumerable <MediaTypeFormatter> formatters)
        {
            if (formatters == null)
            {
                throw Fx.Exception.ArgumentNull("formatters");
            }

            Type paramType = responseContentParameter == null ?
                             TypeHelper.VoidType :
                             responseContentParameter.Type;

            if (paramType == TypeHelper.VoidType)
            {
                this.responseMessageConverter = voidHttpResponseMessageConverter;
                this.outputParameter          = HttpParameter.ResponseMessage;
            }
            else
            {
                paramType = HttpTypeHelper.GetHttpResponseOrContentInnerTypeOrNull(paramType) ?? paramType;

                if (HttpTypeHelper.IsHttpRequest(paramType))
                {
                    throw Fx.Exception.AsError(
                              new InvalidOperationException(
                                  SR.InvalidParameterForContentHandler(
                                      HttpParameter.HttpParameterType.Name,
                                      responseContentParameter.Name,
                                      responseContentParameter.Type.Name,
                                      responseContentHandlerType.Name)));
                }

                Type outputParameterType = HttpTypeHelper.IsHttp(paramType) ? paramType : HttpTypeHelper.MakeHttpResponseMessageOf(paramType);
                this.outputParameter = new HttpParameter(responseContentParameter.Name, outputParameterType);

                this.inputParameter = responseContentParameter;

                if (HttpTypeHelper.IsHttpResponse(paramType))
                {
                    this.responseMessageConverter = simpleHttpResponseMessageConverter;
                }
                else if (HttpTypeHelper.IsHttpContent(paramType))
                {
                    this.responseMessageConverter = httpContentMessageConverter;
                }
                else
                {
                    Type            closedConverterType = httpResponseMessageConverterGenericType.MakeGenericType(new Type[] { paramType });
                    ConstructorInfo constructor         = closedConverterType.GetConstructor(Type.EmptyTypes);
                    this.responseMessageConverter = constructor.Invoke(null) as HttpResponseMessageConverter;
                }
            }

            this.Formatters = new MediaTypeFormatterCollection(formatters);
        }
Exemplo n.º 11
0
        public async Task<ServerResponse> UpdateMessage(int id, string newMessage)
        {
            using (var client = new HttpClient())
            {
                InitializeClient(client);

                var response = await client.PutAsJsonAsync(string.Format("api/messenger/message/{0}", id), newMessage);

                return HttpResponseMessageConverter.ConvertToServerResponse(response);
            }
        }
Exemplo n.º 12
0
        public QuestionsViewModel(PageService pageService, UserService userService, QuestionsRestClient questionsClient)
        {
            _pageService = pageService;
            _userService = userService;

            _questionsClient = questionsClient;

            if (TestId != null)
            {
                Questions = new ObservableCollection <dynamic>(HttpResponseMessageConverter.GetResult <List <dynamic> >(_questionsClient.GetQuestionsByTestId((int)TestId)));
            }
        }
        public DetailsOfTheTestViewModel(PageService pageService, DetailsOfTheTestRestClient detailsOfTheClient)
        {
            _pageService = pageService;

            _detailsOfTheClient = detailsOfTheClient;

            if (TestId != null)
            {
                DetailsOfTheTest.Clear();
                DetailsOfTheTest = new ObservableCollection <dynamic>(HttpResponseMessageConverter.GetResult <List <dynamic> >(_detailsOfTheClient.GetDetailsOfTheTest(Convert.ToInt32(TestId))));
            }
        }
Exemplo n.º 14
0
        public AnswersViewModel(PageService pageService, UserService userService, AnswersRestClient answersClient)
        {
            _pageService = pageService;
            _userService = userService;

            _answersClient = answersClient;

            if (QuestionId != null)
            {
                Answers = new ObservableCollection <dynamic>(HttpResponseMessageConverter.GetResult <List <dynamic> >(_answersClient.GetAnswersByQuestionId((int)QuestionId)));
            }
        }
Exemplo n.º 15
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))));
            }
        }
Exemplo n.º 21
0
 public TokenController(IConfiguration configuration)
 {
     _configuration            = configuration;
     _responseMessageConverter = new HttpResponseMessageConverter();
 }