public UserAccount LoadCurrentUser(ISettingsModel settings) { string currentUser = settings.GetValueOrDefault<string>("currentUser", string.Empty); UserAccount currentAccount = this.Accounts.SingleOrDefault(item => item.Username.Equals(currentUser)); if (currentAccount == null) currentAccount = new UserAccount(); return currentAccount; }
public async Task<UserAccount> LoadCurrentUser(ISettingsModel settings) { string currentUser = settings.GetValueOrDefault<string>("currentUser", string.Empty); UserAccount currentAccount = UserAccounts .Where(item => item.Username.Equals(currentUser)) .SingleOrDefault(); if (currentAccount == null) { // return an anonymous, public user. settings.AddOrUpdate("currentUser", string.Empty); settings.SaveSettings(); currentAccount = new UserAccount(); } else { // attach tokens and favorites currentAccount = await AttachAssociationsAsync(currentAccount); if (!currentAccount.AsForumAccessToken().IsActiveAccount) { settings.AddOrUpdate("currentUser", string.Empty); settings.SaveSettings(); } } return currentAccount; }