public void SaveButtonPressed()
 {
     if (_viewModel.SelectedUser != null)
     {
         _client.AddOrUpdateUser((User)_viewModel.SelectedUser);
     }
     LoadItems();
     EditButtonPressed();
 }
Example #2
0
        private void ExecuteOnApplyChanges()
        {
            try
            {
                if (Validate())
                {
                    IsSavingProgress = true;
                    string res;
                    Task.Run((() =>
                    {
                        GlobalBase.CurrentUser.FirstName = UserName;
                        GlobalBase.CurrentUser.LastName = UserLastName;
                        GlobalBase.CurrentUser.Phone = UserPhone;
                        GlobalBase.CurrentUser.Email = UserEmail;
                        GlobalBase.CurrentUser.Bio = UserBio;
                        res = UserServiceClient.AddOrUpdateUser(GlobalBase.CurrentUser);

                        if (_newAvatar != null)
                        {
                            var chatFile = GlobalBase.FileServiceClient.getChatFileById(GlobalBase.CurrentUser.ImageId);
                            if (chatFile == null)
                            {
                                GlobalBase.CurrentUser.ImageId = GlobalBase.FileServiceClient.UploadFile(new FileService.ChatFile()
                                {
                                    Source = CompressionHelper.CompressImage(_newAvatar)
                                });
                                UserServiceClient.AddOrUpdateUser(GlobalBase.CurrentUser);
                            }
                            else
                            {
                                GlobalBase.FileServiceClient.UpdateFileSource(chatFile.Id, CompressionHelper.CompressImage(_newAvatar));
                            }
                        }

                        SetAvatarForUI();

                        if (res == string.Empty)
                        {
                            Application.Current.Dispatcher.Invoke(new Action((() =>
                            {
                                CustomMessageBox.Show(Translations.GetTranslation()["ChangesSaved"].ToString());
                            })));
                        }
                    })).ContinueWith((task =>
                    {
                        IsSavingProgress = false;
                        IsNewChanges = false;
                    }));
                }
            }
            catch (Exception)
            {
            }
        }
Example #3
0
        private void OnApply()
        {
            _oldPass = _restorePasswordSupplier.GetCurrentPassword();
            _newPass = _restorePasswordSupplier.GetNewPassword();

            if (Validate())
            {
                IsResetingNotProgress = false;
                IsResetingProgress    = true;

                var result = string.Empty;

                Task.Run(() =>
                {
                    try
                    {
                        GlobalBase.CurrentUser.Password = AESEncryptor.encryptPassword(_newPass);

                        UserServiceClient.AddOrUpdateUser(GlobalBase.CurrentUser);
                    }
                    catch (Exception ex)
                    {
                        result = ex.Message;
                    }
                }).ContinueWith(task =>
                {
                    if (result == string.Empty)
                    {
                        Application.Current.Dispatcher.Invoke(new Action((() =>
                        {
                            CustomMessageBox.Show(Translations.GetTranslation()["ChangesSaved"].ToString());
                            OnBack();
                            return;
                        })));
                    }
                    else
                    {
                        Application.Current.Dispatcher.Invoke(new Action((() =>
                        {
                            CustomMessageBox.Show(Translations.GetTranslation()["Error"].ToString(), result);
                        })));
                    }
                });
            }
        }
Example #4
0
        private void SendPassWithMail(User user)
        {
            try
            {
                var from = new MailAddress("*****@*****.**"); // make custom mail adress
                var to   = new MailAddress(user.Email);

                var newPas = AESEncryptor.encryptPassword(RandomNumberGenerator.RandomPassword());
                user.Password = newPas;

                UserServiceClient.AddOrUpdateUser(user);

                var message = new MailMessage(from, to);
                message.Subject = "Password restore";
                message.Body    = "Your pass - " + AESEncryptor.decryptPassword(newPas);

                var smtp = new SmtpClient("smtp.gmail.com", 587);
                smtp.Credentials = new NetworkCredential("*****@*****.**", "messageApp1");
                smtp.EnableSsl   = true;
                smtp.SendMailAsync(message);

                Application.Current.Dispatcher.Invoke(new Action((() =>
                {
                    try
                    {
                        CustomMessageBox.Show(Translations.GetTranslation()["RestorePass"].ToString(), Application.Current.Resources.MergedDictionaries[4]["EmailSend"].ToString());
                        IsSending = false;
                    }
                    finally
                    {
                    }
                })));
            }
            finally
            {
            }
        }
Example #5
0
        private void ExecuteOnRegister()
        {
            try
            {
                IsRegisterProgress = true;
                Task.Run(() =>
                {
                    try
                    {
                        var message = string.Empty;
                        if (ValidateOnRegister())
                        {
                            var user = new User()
                            {
                                Login     = UserLogin,
                                Password  = AESEncryptor.encryptPassword(RPassword),
                                FirstName = Name,
                                LastName  = Surname,
                                Email     = Email,
                                Status    = DateTime.Now.ToString()
                            };

                            if (UserServiceClient.GetUserByLogin(UserLogin) == null)
                            {
                                if (UserServiceClient.AddOrUpdateUser(user) == string.Empty)
                                {
                                    Application.Current.Dispatcher.Invoke(new Action((() =>
                                    {
                                        CustomMessageBox.Show(Translations.GetTranslation()["RegisterDone"].ToString());
                                        Clear();
                                        ExecuteOnBackCommand();
                                        return;
                                    })));
                                }
                                else
                                {
                                    message = Translations.GetTranslation()["RegError"].ToString();
                                }
                            }
                            else
                            {
                                message = Translations.GetTranslation()["SameUserExits"].ToString();
                            }

                            if (message != string.Empty)
                            {
                                Application.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    CustomMessageBox.Show(Translations.GetTranslation()["Error"].ToString(), message);
                                }));
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }).ContinueWith(task => { IsRegisterProgress = false; });
            }
            catch (Exception)
            {
            }
        }