Esempio n. 1
0
 private void ButtonSignUp_Click(object sender, RoutedEventArgs e)
 {
     if (Password.Length == 0 || !RepeatedPassword.Equals(Password))
     {
         Utils.showExclamation(INVALID_PASSWORD);
         return;
     }
     if (!Utils.IsEmailValid(emailInput.Text))
     {
         Utils.showExclamation(INVALID_EMAIL);
         return;
     }
     if (addressInput.Text.Length == 0)
     {
         Utils.showExclamation(INVALID_ADDRESS);
         return;
     }
     int phone = 0;
     int.TryParse(phoneInput.Text, out phone);
     UserDTO user = new UserDTO()
     {
         Address = addressInput.Text,
         Email = emailInput.Text,
         Password = Password,
         Name = nameInput.Text,
         Phone = phone
     };
     worker.EnqueueTask(new WorkerTask((args) =>
         {
             var us = args[0] as UserDTO;
             if (us == null)
                 return null;
             try
             {
                 using (var proxy = new WorkChannel())
                 {
                     return proxy.RegisterUser(new UpdateRequest<UserDTO>()
                     {
                         Data = user
                     });
                 }
             }
             catch (Exception exc)
             {
                 return exc;
             }
         },
         (s, x) =>
         {
             var exc = x.Result as Exception;
             if (exc != null)
             {
                 Utils.HandleException(exc);
                 return;
             }
             var res = x.Result as SingleItemResponse<UserDTO>;
             if (res == null)
             {
                 Utils.showExclamation(Utils.Messages.REGISTRATION_FAILED);
                 return;
             }
             else
             {
                 Utils.showInformation(Utils.Messages.REGISTRATION_COMPLETED);
                 this.Close();
                 return;
             }
         }, user));
 }