Beispiel #1
0
        public AdminPresenter(IAdminView view, SchoolDBEntities data, IUser user, ILoginPresenter loginPresenter)
        {
            this.view           = view;
            view.Presenter      = this;
            this.data           = data;
            this.user           = user;
            this.loginPresenter = loginPresenter;

            var admin = user as Model.Admin;

            view.AdminLabelText = admin.admin_firstN + ' ' + admin.admin_lastN;

            view.FillInProfile(new string[] { "Учител", "Ученик", "Родител" });
            view.FillInWhichGrade(new string[] { "8", "9", "10", "11", "12" });
        }
Beispiel #2
0
        public void OnLoginButtonClick()
        {
            // Check if the user input is valid, display info if not.
            if (view.Username == string.Empty)
            {
                view.Message("Моля, въведете вашето потребителско име.", "Внимание", Views.MessageIcon.Warning);
                return;
            }

            if (view.Pass == string.Empty)
            {
                view.Message("Моля, въведете вашата парола.", "Внимание", Views.MessageIcon.Warning);
                return;
            }

            // Check if the username is in the database
            Model.IUser currentUser = null;
            //string typeOfUser = view.TypeOfUser;
            try
            {
                currentUser = (data.Teachers.Where(x => x.username == view.Username).SingleOrDefault() as Model.IUser) ??
                              (data.Parents.Where(x => x.username == view.Username).SingleOrDefault() as Model.IUser) ??
                              data.Admins.Where(x => x.admin_username == view.Username).SingleOrDefault();
            }
            catch (System.Data.Entity.Core.EntityException)
            {
                view.Message("Неуспешна връзка с базата данни. Моля, опитайте отново по-късно. Съжаляваме за причиненото неудобство.", "Грешка", Views.MessageIcon.Error);
                return;
            }

            // Display error message if there is no such user.
            if (currentUser == null)
            {
                view.Message("Грешно потребителско име и/или парола. Моля, опитайте отново. Ако продължавате да изпитвате затруднения, свържете се с училищния администратор.", "Грешка", Views.MessageIcon.Error);
                return;
            }

            // Instantiate a new password hashing/checking class and use it to check if the user password is correct.
            Utilities.IPasswordHash passHashChecker = new Utilities.PasswordHash();
            var isPasswordCorrect = passHashChecker.Verify(view.Pass, currentUser.Password);

            // Disaply error if password is not correct
            if (!isPasswordCorrect)
            {
                view.Message("Грешно потребителско име и/или парола. Моля, опитайте отново.", "Грешка", Views.MessageIcon.Error);
                return;
            }

            // If everything is fine, hide this view and start the appropriate one. (Not implemented)
            view.Hide();
            //view.Close();

            switch (currentUser.UserType)
            {
            case Model.UserType.Teacher:
                Views.ITeacherView teacherView      = view.CreateTeacherView();
                ITeacherPresenter  teacherPresenter = PresenterFactory.GetTeacherPresenter(teacherView, data, currentUser, this);
                teacherPresenter.Start();
                break;

            case Model.UserType.Parent:
                Views.IParentView parentView      = view.CreateParentView();
                IParentPresenter  parentPresenter = PresenterFactory.GetParentPresenter(parentView, data, currentUser, this);
                parentPresenter.Start();
                break;

            case Model.UserType.Admin:
                Views.IAdminView adminView      = view.CreateAdminView();
                IAdminPresenter  adminPresenter = PresenterFactory.GetAdminPresenter(adminView, data, currentUser, this);
                adminPresenter.Start();
                break;
            }
        }
Beispiel #3
0
 public static IAdminPresenter GetAdminPresenter(Views.IAdminView view, Model.SchoolDBEntities data, Model.IUser currentUser, ILoginPresenter loginPresenter) => new AdminPresenter(view, data, currentUser, loginPresenter);