Esempio n. 1
0
        public void DeleteAccount()
        {
            try
            {
                if (Account == null)
                {
                    return;
                }

                if (!DialogService.Confirm("Are you sure you want to delete this account even though it cannot be undone?"))
                {
                    return;
                }

                if (Account.IsPersisted)
                {
                    StorageService.DeleteAccount(Password, Account.AccountName);
                }

                Status = $"'{Account.AccountName}' account deleted!";

                AccountViewModels.Remove(Account);

                Account = AccountViewModels.FirstOrDefault();
            }
            catch (Exception e)
            {
                DialogService.Exception(e);
            }
        }
Esempio n. 2
0
        public void ImportAccounts()
        {
            try
            {
                if (AccountViewModels.Any(vm => vm.HasChanges))
                {
                    DialogService.Notify("You have unsaved changes. Please save changes before importing accounts.");

                    return;
                }

                using (var dialog = new OpenFileDialog
                {
                    Filter = "JSON files (*.json)|*.json"
                })
                {
                    if (dialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    var json = File.ReadAllText(dialog.FileName);

                    var data = JsonConvert.DeserializeObject <Dtos.AccountDto[]>(json);

                    string dencrypt(string text) => CryptoService.Decrypt(StorageService.GetSecretKey(Password), text);

                    foreach (var item in data)
                    {
                        var found = AccountViewModels.Any(vm => vm.AccountName == item.AccountName);

                        item.AccountName = found ? $"{item.AccountName} - duplicate" : item.AccountName;

                        AccountViewModels.Add(new AccountViewModel(item, dencrypt, true));
                    }

                    Account = AccountViewModels.FirstOrDefault();

                    Status = "Accounts imported...";
                }
            }
            catch (Exception e)
            {
                DialogService.Exception(e);
            }
        }
Esempio n. 3
0
        protected override void OnViewReady(object view)
        {
            base.OnViewReady(view);

            try
            {
                string dencrypt(string text) => CryptoService.Decrypt(StorageService.GetSecretKey(Password), text);

                var items = StorageService.GetAllAccounts(Password).OrderBy(x => x.AccountName);

                foreach (var item in items)
                {
                    AccountViewModels.Add(new AccountViewModel(item, dencrypt));
                }

                Account = AccountViewModels.FirstOrDefault();
            }
            catch (Exception e)
            {
                DialogService.Exception(e);
            }
        }