Пример #1
0
        public async void AddVariantQuestion()
        {
            var question = new VariantQuestionModel()
            {
                Content = "Choose an answer!",
                Enabled = true,
                TopicId = 1,
                Type = QuestionType.Radio,
                UserId = 1,
                Variants = new List<VariantModel>()
                {
                    new VariantModel() { Body = "Answer A", Correct = false},
                    new VariantModel() { Body = "Answer B", Correct = false},
                    new VariantModel() { Body = "Answer C", Correct = true},
                }
            };

            IAccountService accountService = new AccountService();
            var resp = await accountService.Authenticate("*****@*****.**", "ion123");
            IQuestionsService service = new QuestionsService(resp.access_token, new JsonSerializer());
            Assert.IsTrue(service.AddQuestion(question.TopicId, question).Result);
        }
        private async void SignInButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (_isAuthenticationBegun)
                return;

            _isAuthenticationBegun = true;

            string email = "ionh";
            string password = "******";

            if (string.IsNullOrWhiteSpace(email) || string.IsNullOrWhiteSpace(password))
                return;
            try
            {
                IAccountService accountService = new AccountService();
                var response = await accountService.Authenticate(email, password);

                if (!string.IsNullOrEmpty(response?.access_token))
                {
                    IQuestionsService questionsService = new QuestionsService(response.access_token, new JsonSerializer());
                    var question = new VariantQuestionModel()
                    {
                        Content = "Choose an answer!",
                        Enabled = true,
                        TopicId = 1,
                        Type = QuestionType.Radio,
                        UserId = 1,
                        Variants = new List<VariantModel>
                        {
                            new VariantModel() { Body = "Answer A", Correct = false},
                            new VariantModel() { Body = "Answer B", Correct = false},
                            new VariantModel() { Body = "Answer C", Correct = true},
                         }
                    };
                    var result = await questionsService.AddQuestion(question.TopicId, question);
                    MessageBox.Show(result.ToString());

                    IUsersService usersService = new UsersService(response.access_token,
                        new JsonSerializer());
                    UserModel user = await usersService.GetUser();

                    if (!user.Roles.Any(
                            r => r.Equals(RoleType.Teacher.ToString())
                                || r.Equals(RoleType.Admin.ToString())))
                        return;

                    lock (AuthenticationMonitor)
                    {
                        var mainWindow = new MainWindow(accountService);
                        Close();
                        mainWindow.Show();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                //MessageBox.Show(ex.ToString());
            }

            _isAuthenticationBegun = false;
        }