Ejemplo n.º 1
0
        public ResultTable(object mainWindow)
        {
            InitializeComponent();
            SetResultTable(App.CurrentUser);

            performWindow     = mainWindow as PerformWindow;
            constructorWindow = mainWindow as ConstructorWindow;
        }
Ejemplo n.º 2
0
        public TestConstructor(ConstructorWindow constructor, Test test)
        {
            constructorWindow = constructor;
            InitializeComponent();

            using (AppDbContext db = new AppDbContext())
            {
                DataContext = currentTest = db.Tests.Find(test.Id);
            }
        }
        public QuestionConstructor(ConstructorWindow constructor, Question question)
        {
            constructorWindow = constructor;
            InitializeComponent();

            using (AppDbContext db = new AppDbContext())
            {
                DataContext             = currentQuestion = db.Questions.Find(question.Id);
                answersList.ItemsSource = answersCollection = new ObservableCollection <Answer>(currentQuestion.Answers.ToList());
            }
        }
Ejemplo n.º 4
0
        private void Login()
        {
            try
            {
                string username = logLoginTextBox.Text;
                string password = logPasswordTextBox.Password;

                LoginModel loginModel = new LoginModel()
                {
                    Login = username, Password = password
                };

                if (Validation.TryValidateObject(loginModel, logLoginTextBox, logPasswordTextBox, null))
                {
                    using (AppDbContext db = new AppDbContext())
                    {
                        var user = db.Users.FirstOrDefault(u => u.Username == username);
                        if (user != null)
                        {
                            if (SaltedHash.Verify(user.Salt, user.Hash, password))
                            {
                                App.CurrentUser = user;

                                if (user.IsTeacher)
                                {
                                    ConstructorWindow constructorWindow = new ConstructorWindow();
                                    Close();
                                    constructorWindow.Show();
                                }
                                else
                                {
                                    PerformWindow performWindow = new PerformWindow();
                                    Close();
                                    performWindow.Show();

                                    if (user.Level == null)
                                    {
                                        LevelWindow levelWindow = new LevelWindow(performWindow);
                                        levelWindow.Show();
                                    }
                                }
                            }
                            else
                            {
                                logPasswordTextBox.BorderBrush = new SolidColorBrush(Colors.Red);
                                logPasswordTextBox.ToolTip     = new ToolTip()
                                {
                                    Content = "Wrong password"
                                };
                            }
                        }
                        else
                        {
                            logLoginTextBox.BorderBrush = new SolidColorBrush(Colors.Red);
                            logLoginTextBox.ToolTip     = new ToolTip()
                            {
                                Content = "User with this username is not found"
                            };
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
            }
        }