/// <summary> /// Adds a new account. /// </summary> /// <param name="userAccount"> The account to add.</param> /// <returns> Returns true to add, else false.</returns> public bool AddAccount(Account userAccount) { if ( _syncUserstore[userAccount.Username] == null ) { // add _syncUserstore.Add(userAccount.Username, userAccount); _accounts.Add(userAccount); return true; } else { // already exists, change username. return false; } }
/// <summary> /// Gets the account. /// </summary> /// <param name="username"> The username to lookup.</param> public Account GetAccount(string username) { DataSet accountDataSet = SqlHelper.ExecuteDataset(_connectionString, "GetUser", username); Account account = null; if ( accountDataSet.Tables.Count > 0 ) { if ( accountDataSet.Tables[0].Rows.Count > 0 ) { // Create Account object account = new Account(); account.Username = Convert.ToString(accountDataSet.Tables[0].Rows[0]["Username"]); account.Name = Convert.ToString(accountDataSet.Tables[0].Rows[0]["Name"]); //account = accountDataSet.Tables[0].Rows[0]["Password"]; account.Email = Convert.ToString(accountDataSet.Tables[0].Rows[0]["Email"]); account.Created = Convert.ToDateTime(accountDataSet.Tables[0].Rows[0]["Created"]); account.Updated = Convert.ToDateTime(accountDataSet.Tables[0].Rows[0]["Updated"]); } } return account; }
/// <summary> /// Creates a new account. /// </summary> /// <param name="user"> The account type.</param> public void CreateAccount(Account user) { SqlHelper.ExecuteNonQuery(_connectionString, "InsertUser", user.Username, user.Name, user.Password, user.Email, user.Created, user.Created); }
/// <summary> /// Returns true if the user exists, else false. /// </summary> /// <param name="account"> The account to lookup.</param> /// <returns> True if found, else false.</returns> public bool UserExists(Account account) { SqlParameter[] param = new SqlParameter[2]; param[0] = new SqlParameter("@Username", SqlDbType.VarChar,20); param[0].Value = account.Username; param[1] = new SqlParameter("@Found", SqlDbType.Int); param[1].Direction = ParameterDirection.ReturnValue; SqlHelper.ExecuteNonQuery(_connectionString,CommandType.StoredProcedure, "IsUserAvailable",param); int count = (int)param[1].Value; if ( count == 1 ) { return true; } else { return false; } }
/// <summary> /// Updates the account. /// </summary> /// <param name="user"> The account type.</param> public void UpdateAccount(Account user) { SqlHelper.ExecuteNonQuery(_connectionString, "UpdateUser", user.Username, user.Name, user.Email, user.Password); }
/// <summary> /// Creates a new AccountMessage. /// </summary> /// <param name="account"> The Account type.</param> public AccountMessage(Account account) { _account = account; }
/// <summary> /// Removes an account. /// </summary> /// <param name="userAccount"> The account to remove.</param> /// <returns> Returns true if removed, else false.</returns> public bool RemoveAccount(Account userAccount) { if ( _syncUserstore[userAccount.Username] != null ) { Account removeAccount = (Account)_syncUserstore[userAccount.Username]; // remove _syncUserstore.Remove(userAccount.Username); _accounts.Remove(removeAccount); return true; } else { // not found. return false; } }