Ejemplo n.º 1
0
 internal void UpdateEntity(User user, UserDTO userDto)
 {
     user.Address = userDto.Address;
     user.Email = userDto.Email;
     user.Name = userDto.Name;
     user.Phone = userDto.Phone;
     user.Rights = userDto.Rights;
 }
Ejemplo n.º 2
0
 public void UpdateWithUserDTO(UserDTO userDto)
 {
     this.UserID = userDto.UserID;
     this.Address = userDto.Address;
     this.Email = userDto.Email;
     this.Phone = userDto.Phone;
     this.Rights = userDto.Rights;
     this.Name = userDto.Name;
     this.Password = userDto.Password;
 }
Ejemplo n.º 3
0
 internal void UpdateEntityUserLevel(User user, UserDTO userDto)
 {
     if (userDto.Address != null)
         user.Address = userDto.Address;
     if (userDto.Name != null)
         user.Name = userDto.Name;
     if (userDto.Password != null)
         user.Password = GetHashedPassword(userDto.Password);
     if (userDto.Phone >= 0)
         user.Phone = userDto.Phone;
 }
Ejemplo n.º 4
0
 public User ToUser(UserDTO user)
 {
     return new User
     {
         Email = user.Email,
         Name = user.Name,
         Address = user.Address,
         Phone = user.Phone,
         Rights = 1,
         Password = GetHashedPassword(user.Password)
     };
 }
Ejemplo n.º 5
0
 private bool HasRights(UserDTO userDTO, int p)
 {
     return userDTO != null && userDTO.Rights >= p;
 }
Ejemplo n.º 6
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));
 }
Ejemplo n.º 7
0
 internal void SaveUserInfo()
 {
     Worker.EnqueueTask(new WorkerTask(args =>
         {
             try
             {
                 using (var proxy = new WorkChannel())
                 {
                     var data = new UserDTO
                     {
                         UserID = User.UserID,
                         Address = User.Address,
                         Email = User.Email,
                         Name = User.Name,
                         Password = null,
                         Phone = User.Phone,
                         Rights = User.Rights
                     };
                     return proxy.UpdateUser(new UpdateRequest<UserDTO>()
                     {
                         Login = User.Email,
                         Password = User.Password,
                         Data = data
                     });
                 }
             }
             catch (Exception exc)
             {
                 return exc;
             }
         }, (s, e) =>
         {
             if (e.Result is Exception)
             {
                 Utils.HandleException(e.Result as Exception);
                 return;
             }
             var userRes = e.Result as SingleItemResponse<UserDTO>;
             if (userRes == null)
             {
                 Utils.showError(Utils.Messages.UNKNOWN_ERROR_FORMAT);
                 return;
             }
             ClientConfig.CurrentUser.UpdateWithUserDTO(userRes.Data);
             ClientConfig.CurrentUser.RefreshRate = this.User.RefreshRate;
             this.User = ClientConfig.CurrentUser;
             ModifiedUserData = false;
             Utils.showInformation(Utils.Messages.SAVED_SUCCESSFULLY);
         }, null));
 }