/// <summary> /// Checks if account is already in database. /// </summary> /// <param name="accountItem">Account item to check.</param> /// <returns>True if account is already in database, false otherwise.</returns> public bool CheckIfAccountAlreadyExists(AccountItem accountItem) { try { var accounts = AccountService.GetAccountsAsync(); return(accounts.Any(a => a.UserName == accountItem.UserName)); } catch (Exception e) { Console.WriteLine("Error Message : " + e.ToString()); return(false); } }
/// <summary> /// Deletes the account information from the database. /// </summary> /// <param name="accountItem"> Account item to sign out.</param> public void AccountSignOut(AccountItem accountItem) { try { if (accountItem == null) { throw new ArgumentNullException(nameof(accountItem)); } // GetAccountByID return account instance with reference to the given ID Account account = AccountService.GetAccountById(accountItem.AccountId); // Deletes the account information from the account DB. AccountService.DeleteAccount(account); } catch (Exception e) { Console.WriteLine("Error Message : " + e.ToString()); } }
/// <summary> /// Adds an account with UserId and UserPassword received from accountItem. /// You should get these from server communication in actual account provider. /// </summary> /// <param name="accountItem"> Account item to add.</param> /// <returns> The account ID of the account instance. </returns> public int AccountAdd(AccountItem accountItem) { if (accountItem == null) { throw new ArgumentNullException(nameof(accountItem)); } try { int id = -1; // Create account instance Account account = Account.CreateAccount(); if (account == null) { return(id); } // Add account with inputed id and password. // In sample app, just add id as user_name and password as access_token. // But, you should get these from server communication in actual account provider. account.UserName = accountItem.UserName; account.AccessToken = accountItem.UserPassword; account.SyncState = AccountSyncState.Idle; // Insert account DB with the new account information. // AddAccount returns account id. id = AccountService.AddAccount(account); return(id); } catch (Exception e) { Console.WriteLine("Error Message : " + e.ToString()); return(-1); } }
/// <summary> /// Gets AccountId from database for selected account item. /// </summary> /// <param name="account">Account item to find in database.</param> /// <returns>Returns AccountId for account item. Returns -1 if /// account with specified userId and userPass doesn't exists in database or /// when error occurred.</returns> public int GetAccountId(AccountItem account) { try { var accounts = AccountService.GetAccountsByUserName(account.UserName); var foundAccount = accounts.FirstOrDefault( a => a.AccessToken == account.UserPassword); if (foundAccount != null) { return(foundAccount.AccountId); } else { return(-1); } } catch (Exception e) { Console.WriteLine("Error Message : " + e.ToString()); return(-1); } }