/// <summary> /// makes logout /// normally this is called from window (application) close /// </summary> public void ClearSession() { using (JolTudomEWSClient WSClient = new JolTudomEWSClient()) { try { if (!string.IsNullOrEmpty(_Token)) { WSClient.Logout(_Token); _Token = string.Empty; LoggedInUser = null; } } catch (FaultException<ExceptionDetail> exc) { // this is OK, the session is expired, or not available if (!ExceptionHandler.IsSessionNotAvailableException(exc)) { // otherwise throw the exception throw; } } } }
public bool Login(string username, string password, out string ErrorMess) { ErrorMess = string.Empty; using (JolTudomEWSClient WSClient = new JolTudomEWSClient()) { try { PersonDetails pd = new PersonDetails(); _Token = WSClient.Login(out pd, username, password); LoggedInUser = pd; Messenger.Default.Send<AfterLoginLogoutMessage>(new AfterLoginLogoutMessage()); Messenger.Default.Send<NavigationMessage>(new NavigationMessage { View = ViewEnum.Student }); } catch (FaultException fe) { ErrorMess = fe.Message; } } return ErrorMess == string.Empty; }
/// <summary> /// makes logout, and navigates to Login View /// </summary> public void Logout() { using (JolTudomEWSClient WSClient = new JolTudomEWSClient()) { try { WSClient.Logout(_Token); _Token = string.Empty; LoggedInUser = null; Messenger.Default.Send<AfterLoginLogoutMessage>(new AfterLoginLogoutMessage()); Messenger.Default.Send<NavigationMessage>(new NavigationMessage { View = ViewEnum.Login }); } catch (FaultException<ExceptionDetail> exc) { // this is OK, the session is expired, or not available if (ExceptionHandler.IsSessionNotAvailableException(exc)) { Messenger.Default.Send<AfterLoginLogoutMessage>(new AfterLoginLogoutMessage()); Messenger.Default.Send<NavigationMessage>(new NavigationMessage { View = ViewEnum.Login, UserState = "SessionExpired" }); } else // otherwise throw the exception throw; } } }
public StudentViewModel(WSManager ds):base(ds) { NumberQuestion = 15; if (IsInDesignMode) { _LoggedInPerson = new PersonDetails() { PersonID = 1, FirstName = "jozsika" }; TestResultCaption = string.Format("Eddigi Tesztek Eredményei: {0}", _LoggedInPerson.TreeDisplayName); ErrorMsg = "Ez meg az error"; ShowPersonList = true; StatisticList = new ObservableCollection<Statistics>(); StatisticList.Add(new Statistics { Generated = DateTime.Now, TestID = 2, Questions = 15, CorrectAnswer = 3, Percent = 3, TotalTime = TimeSpan.FromSeconds(69) }); PersonTreeList = new List<PersonRole>(); PersonTreeList.Add(new PersonRole { RoleName = "Saját", Children = new List<PersonDetails>() { _LoggedInPerson } }); PersonTreeList.Add(new PersonRole { RoleName = "Diák", Children = new List<PersonDetails>() { new PersonDetails { FirstName = "vki", LastName = "vki" } } }); } else { } }
protected override void LoadData() { try { // show the New Test Start controls if we have error message from the Test Execution initialization // otherwise hide it IsNewTestExpanded = !string.IsNullOrEmpty(ErrorMsg); // has to save the ErrorMsg to temp variable // because if the StudentView is called back from TestExecution, but we had error there at NewTest // the Error from that VM has to show here var olderror = ErrorMsg; _LoggedInPerson = (PersonDetails)_DataService.LoggedInUser; if (_LoggedInPerson.RoleEnum == PersonRoleEnum.Student) { // this is the student TestResultCaption = string.Format("Eddigi Tesztek Eredményei: {0}", _LoggedInPerson.TreeDisplayName); ShowPersonList = false; StatisticList = new ObservableCollection<Statistics>(_DataService.GetStatistics(null)); } else if (_LoggedInPerson.RoleEnum == PersonRoleEnum.Teacher) { // this is teacher ShowPersonList = true; // ask only for students PersonTreeList = _DataService.GetUsers((int)PersonRoleEnum.Student); SelectedUser = PersonTreeList.Find(p => p.RoleName == "Saját").Children[0]; } else if (_LoggedInPerson.RoleEnum == PersonRoleEnum.Admin) { // this is admin ShowPersonList = true; // ask for everybody PersonTreeList = _DataService.GetUsers(null); SelectedUser = PersonTreeList.Find(p => p.RoleName == "Saját").Children[0]; } CourseList = _DataService.GetCourses(); ErrorMsg = olderror; } catch (SessionExpiredException) { MessengerInstance.Send<NavigationMessage>(new NavigationMessage { View = ViewEnum.Login, UserState = "SessionExpired" }); } }