private async void Connect() { IsLoadingSession = true; await Task.Run(() => { try { bool connect = _loginBM.Connect(Login, Password); if (connect) { DispatchService.Invoke(() => PageMediator.Notify("Change_MainWindow_UC", EUserControl.MAIN, Login)); } else { Message = "Wrong username or password"; } } catch (System.Exception e) { if (e is CustomServerException) { DispatchService.Invoke(() => ShowRetryWindow()); } } finally { IsLoadingSession = false; } }); }
/// <summary> /// Add asynchronously a patient /// </summary> /// <returns></returns> private async Task AddPatient() { await Task.Run(() => { try { if (!Name.IsNullOrWhiteSpace() && !Firstname.IsNullOrWhiteSpace() && Birthday != null) { Patient patient = new Patient() { Name = Name, Firstname = Firstname, Birthday = Birthday, Observations = new List <Observation>().ToArray() }; if (_patientBM.AddPatient(patient)) { DispatchService.Invoke(() => PageMediator.Notify("Change_Main_UC", EUserControl.MAIN_PATIENTS, _currentLogin)); } else { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.ADD_PATIENT)); } } else { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.MISSING_FIELDS)); } } catch (Exception) { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.ADD_PATIENT)); } }); }
private void LogoutSession() { if (_sessionBM.Disconnect()) { PageMediator.Notify("Change_MainWindow_UC", EUserControl.LOGIN, _login); } else { ShowServerExceptionWindow(); } }
public MainViewModel(string login) { _login = login; _sessionBM = new UserBM(login); LogoutCommand = new RelayCommand(param => LogoutSession(), param => true); UsersViewCommand = new RelayCommand(param => LoadUsersView(), param => true); PatientsViewCommand = new RelayCommand(param => LoadPatientsView(), param => true); InitializeUser(); LoadUsersView(); PageMediator.Register("Change_Main_UC", OnChangeView); }
/// <summary> /// Add new user if fields are corrects /// </summary> private async Task AddUser() { await Task.Run(() => { try { if (!Name.IsNullOrWhiteSpace() && !Firstname.IsNullOrWhiteSpace() && !Password.IsNullOrWhiteSpace() && !Login.IsNullOrWhiteSpace() && !Role.IsNullOrWhiteSpace()) { User user = new User() { Name = Name, Firstname = Firstname, Pwd = Password, Login = Login, Role = Role, Picture = Image, Connected = false }; if (_sessionBM.AddUser(user)) { DispatchService.Invoke(() => PageMediator.Notify("Change_Main_UC", EUserControl.MAIN_USERS, _currentLogin)); } else { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.ADD_USER)); } } else { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.MISSING_FIELDS)); } } catch (Exception e) { if (e is CustomLargePictureException) { DispatchService.Invoke(() => ShowPictureExceptionWindow()); } DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.ADD_USER)); } }); }
/// <summary> /// Show patient information details if patient selected /// </summary> private void ShowPatientDetails() { if (SelectedPatient != null) PageMediator.Notify("Change_Main_UC", Model.Enum.EUserControl.MAIN_PATIENTS_SINGLE, SelectedPatient.Id); }
/// <summary> /// Go to add patient view /// </summary> private void ChangeView() { PageMediator.Notify("Change_Main_UC", Model.Enum.EUserControl.MAIN_PATIENTS_ADD, _currentLogin); }
/// <summary> /// Navigate to user control /// </summary> private void Back() { PageMediator.Notify("Change_Main_UC", EUserControl.MAIN_USERS, _currentLogin); }
public MainWindowViewModel() { CurrentUC = new LoginUC(); PageMediator.Register("Change_MainWindow_UC", OnConnectView); }
/// <summary> /// Go to add user view /// </summary> private void ChangeView() { PageMediator.Notify("Change_Main_UC", EUserControl.MAIN_USERS_ADD, _currentLogin); }