Example #1
0
 public DataManager()
 {
     _ctx = new eDiaryModelDB();
     if (!_ctx.User.Any(x => x.username == "admin"))
     {
         _ctx.User.Add(new User
         {
             user_id          = 0,
             username         = "******",
             password         = "******",
             user_access_rank = 1
         });
         _ctx.SaveChanges();
     }
 }
Example #2
0
        private void LoginClick(object sender, RoutedEventArgs e)
        {
            Username = usernameTextBox.Text;
            Password = passwordTextbox.Password;
            var context   = new eDiaryModelDB();
            var viewModel = new LoginViewModel();

            ViewModel.Password = passwordTextbox.Password;
            viewModel.Login();
            if (ViewModel.Login())
            {
                var user = context.User.FirstOrDefault(x => x.username == Username);
                switch (user.user_access_rank)

                {
                case 1:
                    AdminView _av = new AdminView();
                    _av.Show();
                    this.Close(); break;

                case 2:
                    MainWindow teacherView = new MainWindow();
                    teacherView.Show();
                    this.Close(); break;

                case 3:

                    MainWindow studentView = new MainWindow();
                    studentView.Show();
                    this.Close(); break;

                default: MessageBox.Show("ERROR 404"); break;
                }
            }
            else
            {
                MessageBox.Show("Nem megfelelő adatok");
            }
            //switch ()
            //{
            //    case 1:
            //        AdminView adminview = new AdminView();
            //        adminview.Show();
            //        this.Close(); break;

            //    case 2:
            //        Username = usernameTextBox.Text;
            //        Password = passwordTextbox.Password;
            //        MainWindow teacherView = new MainWindow();
            //        teacherView.Show();
            //        this.Close(); break;

            //    case 3:
            //        Username = usernameTextBox.Text;
            //        Password = passwordTextbox.Password;
            //        MainWindow studentView = new MainWindow();
            //        studentView.Show();
            //        this.Close(); break;

            //    default: MessageBox.Show("ERROR 404"); break;
            //}


            //var user = context.User.FirstOrDefault(x => x.username == username);
            //if (user != null)
            //{
            //    if (user.password == password)
            //    {
            //        switch (user.user_access_rank)
            //        {
            //            case 1:
            //                AdminView adminview = new AdminView();
            //                adminview.Show();
            //                this.Close(); break;

            //            case 2:
            //                MainWindow teacherView = new MainWindow();
            //                teacherView.Show();
            //                this.Close(); break;

            //            case 3:
            //                MainWindow studentView = new MainWindow();
            //                studentView.Show();
            //                this.Close(); break;

            //            default: MessageBox.Show("ERROR 404"); break;
            //        }

            //    }
            //    else
            //        MessageBox.Show("Rossz felhasználónév vagy jelszó");

            //}
            //else
            //    MessageBox.Show("Rossz felhasználónév vagy jelszó");
        }