public TeacherPresenter(Views.ITeacherView view, Model.SchoolDBEntities data, Model.IUser user, ILoginPresenter loginPresenter) { this.view = view; view.Presenter = this; this.data = data; this.user = user; this.loginPresenter = loginPresenter; var teacher = user as Model.Teacher; view.TeacherNameLabelText = teacher.teacher_firstN + ' ' + teacher.teacher_lastN; var subject = teacher.Subjects.Select(x => Tuple.Create(x.subject_id, x.subject_name)); view.FIllInCorrespondingSubjects(subject.ToList()); view.ComboBoxSubjectSelectedIndex = -1; view.ComboBoxStudentSelectedIndex = -1; view.FillInGrades(new string[] { "6", "5", "4", "3", "2" }); view.FillInWhichGrade(new string[] { "8", "9", "10", "11", "12" }); }
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; } }
public static ITeacherPresenter GetTeacherPresenter(Views.ITeacherView view, Model.SchoolDBEntities data, Model.IUser currentUser, ILoginPresenter loginPresenter) => new TeacherPresenter(view, data, currentUser, loginPresenter);