Esempio n. 1
0
 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"
     });
 }
Esempio n. 2
0
 public static ApplicationResult CreateAccount(string alias, string currencyType, string accountType, decimal amount = 0)
 {
     if (AccountManager.Data.Exists(account => account.Type == accountType))
     {
         return(new ApplicationResult {
             Success = false,
             Message = "Account with such name already exists"
         });
     }
     if (!AccountCurrency.Exists(currencyType))
     {
         return(new ApplicationResult {
             Success = false,
             Message = $"Currency {currencyType} is not supported"
         });
     }
     AccountManager.AddAccount(new AccountCurrency(currencyType, amount), accountType, alias);
     AccountManager.UpdateData();
     return(new ApplicationResult {
         Success = true,
         Message = $"Account successfully created"
     });
 }