public async void AddWalletCategory() { try { if (SelectedCategory == null) { MessageBox.Show("Please,select the category."); return; } IsEnabled = false; FromWallet.Categories.Add(SelectedCategory); await Task.Run(() => _walService.AddOrUpdateWalletAsync(FromWallet)); UpdateListsOfCategories(); MessageBox.Show("Adding wallet category completed!"); } catch (Exception ex) { MessageBox.Show($"Adding wallet category failed {ex.Message}"); } finally // is done independently from exception { IsEnabled = true; } }
//TODO: MAKE ADDING WALLET REALLY ASYNC public async void AddWallet() { try { IsEnabled = false; if (String.IsNullOrWhiteSpace(_wallet.Name)) { MessageBox.Show("Name of wallet is empty."); return; } Wallet addWallet = new Wallet(CurrentInformation.User.Guid, _wallet.Name, _wallet.Balance, _wallet.Description, _wallet.MainCurrency, _wallet.Transactions, _wallet.Categories, _wallet.CoOwnersGuid); await Task.Run(() => _service.AddOrUpdateWalletAsync(addWallet)); WalletsViewModel.Wallets.Add(new WalletDetailsViewModel(addWallet)); CurrentInformation.User.Wallets.Add(addWallet); MessageBox.Show($"Wallet {addWallet.Name} added to the list of wallets!"); } catch (Exception ex) { MessageBox.Show($"Adding wallet failed {ex.Message}"); } finally // is done independently from exception { IsEnabled = true; } }
private void DeleteCategory() { try { if (SelectedCategory == null) { MessageBox.Show("Please,select the category."); return; } IsEnabled = false; Task.Run(() => _catService.DeleteCategory(SelectedCategory)); CurrentInformation.User.Categories.Remove(SelectedCategory); foreach (Wallet wallet in _walService.GetWallets()) { if (wallet.OwnerGuid == CurrentInformation.User.Guid) { wallet.Categories.Remove(wallet.Categories.ToList().Find(x => x.Name == SelectedCategory.Name && x.Guid == SelectedCategory.Guid)); Task.Run(() => _walService.AddOrUpdateWalletAsync(wallet)); } } MessageBox.Show($"Category {SelectedCategory.Name} removed from the list of categories!"); UpdateUserCategoriesCollection(); } catch (Exception ex) { MessageBox.Show($"Deleting category failed {ex.Message}"); } finally // is done independently from exception { IsEnabled = true; } }