/// <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));
         }
     });
 }
Beispiel #2
0
 /// <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));
         }
     });
 }