Exemple #1
0
        private void UserLoginButton_Click(object sender, RoutedEventArgs e) // When click on the Login button
        {
            User a = new Administrator();                                    // Create a User (set as Administrator because we cannot instanciate a User (abstract). Could be teacher, student...)

            using (var myDb = new VirtualCollegeContext())
            {
                var addresses = myDb.Addresses.ToList();

                var payments = myDb.Payments.ToList();

                var lessons = myDb.Lessons.Include("Students").Include("PresentStudents").ToList();

                var courses = myDb.Courses.Include("Teachers").ToList();

                var grades = myDb.Grades.ToList();

                a = myDb.Users.ToList().Find(u => u.EmailAddress == userLoginInput.Text && u.Password == userPasswordinput.Password.ToString()); // Find the user that has the matching Email-Address/Password
            }

            if (a != null)                              // If we found a user that has the correct combination
            {
                var t = a.GetType().Name.Split('_')[0]; // Gets the type ("Administrator", "Student", "Teacher")
                switch (t)
                {
                case "Student":
                    StudentView studentViewWindow = new StudentView(a);                         // Instanciate the corresponding window
                    studentViewWindow.Closing += new CancelEventHandler(AnyViewWindow_Closing); // Add an argument when the window closes (Cf. Line 410)
                    studentViewWindow.Show();                                                   // Display the window
                    this.Visibility = Visibility.Hidden;                                        // Hide login window as soon as the correct window is displayed
                    break;

                case "Teacher":
                    TeacherView teacherViewWindow = new TeacherView(a);
                    teacherViewWindow.Closing += new CancelEventHandler(AnyViewWindow_Closing);
                    teacherViewWindow.Show();
                    this.Visibility = Visibility.Hidden;
                    break;

                case "Administrator":
                    AdministratorView adminViewWindow = new AdministratorView(a);
                    adminViewWindow.Closing += new CancelEventHandler(AnyViewWindow_Closing);
                    adminViewWindow.Show();
                    this.Visibility = Visibility.Hidden;
                    break;

                default:
                    break;
                }
            }
            else
            {
                MessageBox.Show($"Wrong login and/or password!", "Wrong login", MessageBoxButton.OK, MessageBoxImage.Error);  // If no user was matching, display this error
            }
        }
        private void UserLoginButton_Click(object sender, RoutedEventArgs e)
        {
            User a = new Administrator();

            using (var myDb = new VirtualCollegeContext())
            {
                var addresses = myDb.Addresses.ToList();

                var payments = myDb.Payments.ToList();

                var lessons = myDb.Lessons.Include("Students").Include("PresentStudents").ToList();

                var courses = myDb.Courses.Include("Teachers").ToList();

                var grades = myDb.Grades.ToList();

                a = myDb.Users.ToList().Find(u => u.EmailAddress == userLoginInput.Text && u.Password == userPasswordinput.Password.ToString());
            }

            if (a != null)
            {
                var t = a.GetType().Name.Split('_')[0];
                switch (t)
                {
                case "Student":
                    StudentView studentViewWindow = new StudentView(a);
                    studentViewWindow.Closing += new CancelEventHandler(AnyViewWindow_Closing);
                    studentViewWindow.Show();
                    this.Visibility = Visibility.Hidden;
                    break;

                case "Teacher":
                    TeacherView teacherViewWindow = new TeacherView(a);
                    teacherViewWindow.Closing += new CancelEventHandler(AnyViewWindow_Closing);
                    teacherViewWindow.Show();
                    this.Visibility = Visibility.Hidden;
                    break;

                case "Administrator":
                    AdministratorView adminViewWindow = new AdministratorView(a);
                    adminViewWindow.Closing += new CancelEventHandler(AnyViewWindow_Closing);
                    adminViewWindow.Show();
                    this.Visibility = Visibility.Hidden;
                    break;

                default:
                    break;
                }
            }
            else
            {
                MessageBox.Show($"Wrong login and/or password!", "Wrong login", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }