Пример #1
0
        /// <summary>
        /// Edit this account
        /// </summary>
        private async Task EditAccount()
        {
            // Fill the view Model with the information
            DialogPasswordItemViewModel viewModel = new DialogPasswordItemViewModel {
                Id          = this.Id,
                AccountName = this.AccountName,
                Email       = this.Email,
                Password    = this.Password,
                Username    = this.Username,
                Website     = this.Website,
                Notes       = this.Notes,
            };
            await IoC.UI.ShowModifyDialog(viewModel, "Edit Account");

            // return if the modification was canceled
            if (!viewModel.Success)
            {
                return;
            }

            // Call the database
            UserContentDataModel result = await IoC.ClientDataStore.UpdateUserContentAsync(
                IoC.ApplicationViewModel.RunningLoginInfo,
                new UserContentDataModel {
                Id = viewModel.Id,
                AccountNameHash = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.AccountName),
                EmailHash       = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.Email),
                PasswordHash    = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.Password),
                UsernameHash    = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.Username),
                WebsiteHash     = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.Website),
                NotesHash       = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.Notes),
            }
                );

            // if the response has an error -> display it
            if (result == null)
            {
                await IoC.UI.ShowMessageBoxDialog(new DialogMessageBoxViewModel { Message = "Failed to edit the Account" }, "Error");

                // done
                return;
            }

            // update the values in this ViewModel
            Id          = viewModel.Id;
            AccountName = viewModel.AccountName;
            Email       = viewModel.Email;
            Password    = viewModel.Password;
            Username    = viewModel.Username;
            Website     = viewModel.Website;
            Notes       = viewModel.Notes;
        }
        /// <summary>
        /// Method to add a new password
        /// </summary>
        /// <returns></returns>
        private async Task AddPassword()
        {
            DialogPasswordItemViewModel viewModel = new DialogPasswordItemViewModel();
            await IoC.UI.ShowModifyDialog(viewModel, "Add Password");

            // return if the modification was canceled
            if (!viewModel.Success)
            {
                return;
            }

            // Call the database
            UserContentDataModel result = await IoC.ClientDataStore.AddUserContentAsync(
                IoC.ApplicationViewModel.RunningLoginInfo,
                new UserContentDataModel {
                Id = Guid.NewGuid().ToString("N"),
                AccountNameHash = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.AccountName),
                EmailHash       = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.Email),
                PasswordHash    = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.Password),
                UsernameHash    = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.Username),
                WebsiteHash     = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.Website),
                NotesHash       = Crypt.EncryptString(IoC.ApplicationViewModel.MasterHash, viewModel.Notes),
            }
                );

            // if the response has an error -> display it
            if (result == null)
            {
                await IoC.UI.ShowMessageBoxDialog(new DialogMessageBoxViewModel { Message = "Failed to add Password" }, "Error");

                // done
                return;
            }

            // add the new Account to the view
            Accounts.Add(new PasswordListItemViewModel(this)
            {
                Id          = result.Id,
                AccountName = viewModel.AccountName,
                Email       = viewModel.Email,
                Password    = viewModel.Password,
                Username    = viewModel.Username,
                Website     = viewModel.Website,
                Notes       = viewModel.Notes,
            });
        }