public static ApplicationResult SwitchAccount(string targetAccountType) { if (CurrentAccount != null && targetAccountType == CurrentAccount.Type) { return(new ApplicationResult { Success = false, Message = $"{targetAccountType} is already chosen" }); } var result = AccountManager.Data.FirstOrDefault(acc => acc.Type == targetAccountType); if (result == null) { return(new ApplicationResult { Success = false, Message = $"Type of {targetAccountType} does not exist" }); } AccountActionManager?.Dispose(); CurrentAccount = result; AccountActionManager = new AccountActionManager(CurrentAccount.Id); AccountActionManager.LoadData(); return(new ApplicationResult { Success = true, Message = "Successfully switched" }); }
static Application() { AccountManager = new AccountManager("AccountsData.json"); AccountManager.LoadData(); AccountActionManager = null; if (AccountManager.Data.Count == 0) { CurrentAccount = null; AccountActionManager = null; } else { CurrentAccount = AccountManager.Data[0]; AccountActionManager = new AccountActionManager(CurrentAccount.Id); AccountActionManager.LoadData(); } }