public static ApplicationResult ModifyAccount(string newAccountCurrencyType = null, string newAccountType = null) { if (CurrentAccount == null) { return(new ApplicationResult { Success = false, Message = "No active accounts" }); } if (string.IsNullOrEmpty(newAccountCurrencyType) && string.IsNullOrEmpty(newAccountType)) { return(new ApplicationResult { Success = false, Message = "At least one argument must be non-null" }); } if (newAccountCurrencyType != null && newAccountCurrencyType != CurrentAccount.Currency.Type) { if (!AccountCurrency.Exists(newAccountCurrencyType)) { return(new ApplicationResult { Success = false, Message = $"Currency {newAccountCurrencyType} is not supported" }); } CurrentAccount.Currency.Type = newAccountCurrencyType; foreach (var item in AccountActionManager.Data) { item.Currency.Type = newAccountCurrencyType; } AccountActionManager.UpdateData(); } if (newAccountType != null && newAccountType != CurrentAccount.Type) { if (AccountManager.Data.Exists(acc => acc.Type == newAccountType)) { return(new ApplicationResult { Success = false, Message = $"Account {newAccountType} already exists" }); } CurrentAccount.Type = newAccountType; } AccountManager.UpdateData(); return(new ApplicationResult { Success = true, Message = "Successfully modified the account" }); }
public static ApplicationResult AddIncomeOrExpense(AccountActionType actionType, string currencyType, decimal amount, string category, string note) { if (amount <= 0) { return(new ApplicationResult { Success = false, Message = "Amount cannot be zero or less than zero" }); } if (currencyType.ToLower() == "auto") { currencyType = CurrentAccount.Currency.Type; } var currentAccountCurrency = CurrentAccount.Currency; if (currencyType != CurrentAccount.Currency.Type) { try { var result = AccountCurrency.Convert(currencyType, CurrentAccount.Currency.Type, amount); DoIncomeOrExpenseOperation(actionType, currentAccountCurrency, result); AccountActionManager.AddAccountAction(new AccountAction(actionType, new AccountCurrency(CurrentAccount.Currency.Type, result), category, note)); AccountActionManager.UpdateData(); AccountManager.UpdateData(); } catch (BadConversionException ex) { return(new ApplicationResult { Success = false, Message = ex.Message }); } return(new ApplicationResult { Success = true, Message = "Successfully converted and added" }); } DoIncomeOrExpenseOperation(actionType, currentAccountCurrency, amount); AccountActionManager.AddAccountAction(new AccountAction(actionType, new AccountCurrency(currencyType, amount), category, note)); AccountActionManager.UpdateData(); AccountManager.UpdateData(); return(new ApplicationResult { Success = true, Message = "Successfully added" }); }