public AccountViewModel(AccountModel m) { this.accountId = m.AccountId; this.username = m.Username; this.email = m.Email; this.active = m.Active; this.locked = m.Locked; this.success = m.Success; this.message = m.Message; }
/// <summary> /// Get all account information per account by row /// </summary> /// <param name="row"></param> /// <returns>The account information</returns> private AccountModel getAccountFromDataRow(DataRow row) { AccountModel model = new AccountModel(); //checking if account successfully logged in model.AccountId = Convert.ToInt32(row["Accountid"] ?? 0); if(row["DateCreated"] != null) model.DateCreated = DateTime.Parse(row["DateCreated"].ToString()); model.Active = Convert.ToBoolean(row["Active"] ?? false); model.Email = Convert.ToString(row["Email"] ?? ""); model.Locked = Convert.ToBoolean(row["Locked"] ?? false); model.Username = Convert.ToString(row["Username"] ?? ""); return model; }
public AccountModel Register(RegistrationModel model) { SqlCommand command = new SqlCommand("AccountCreate", new SqlConnection(this.connectionString)); command.Parameters.AddWithValue("@Username", model.Username); command.Parameters.AddWithValue("@Email", model.Email); command.Parameters.AddWithValue("@Password", model.Password); command.Parameters.AddWithValue("@Salt", model.Salt); command.Parameters.AddWithValue("@IpAddress", model.IpAddress ?? ""); DataSet dsResult = DataTools.RunStoredProcedure(command); AccountModel acct = new AccountModel(); if (dsResult.Tables[1] != null) { if (dsResult.Tables[1].Rows.Count > 0) { acct = getAccountFromDataRow(dsResult.Tables[1].Rows[0]); } } if (dsResult.Tables[0].Rows[0]["Message"] != null) acct.Message = Convert.ToString(dsResult.Tables[0].Rows[0]["Message"]); if (dsResult.Tables[0].Rows[0]["Success"] != null) acct.Success = Convert.ToBoolean(dsResult.Tables[0].Rows[0]["Success"]); return acct; }
/// <summary> /// Update account info if there were changes /// </summary> /// <param name="account"></param> /// <returns></returns> public AccountModel UpdateAccount(AccountModel account) { //These are commands that are probably needed for this function. SqlCommand command = new SqlCommand("UpdateAccount", new SqlConnection(connectionString)); command.Parameters.AddWithValue("@AccountId", account.AccountId); command.Parameters.AddWithValue("@Username", account.Username); command.Parameters.AddWithValue("@Email", account.Email); command.Parameters.AddWithValue("@Active", account.Active); command.Parameters.AddWithValue("@Locked", account.Locked); command.Parameters.AddWithValue("@Salt", account.Salt); command.Parameters.AddWithValue("@Password", account.Password); DataSet dsResult = DataTools.RunStoredProcedure(command); AccountModel acct = getAccountFromDataRow(dsResult.Tables[0].Rows[0]); return acct; }
//Successfully tested. runs fine /// <summary> /// Get login information and validates against database /// </summary> /// <param name="loginModel"></param> /// <returns></returns> public AccountModel Login(LoginModel loginModel) { SqlCommand command = new SqlCommand("AccountLogin", new SqlConnection(this.connectionString)); command.Parameters.AddWithValue("@LoginName", loginModel.LoginName); command.Parameters.AddWithValue("@Password", loginModel.Password); DataSet dsResult = DataTools.RunStoredProcedure(command); AccountModel acct = new AccountModel(); try { acct = getAccountFromDataRow(dsResult.Tables[1].Rows[0]); } catch { } //check for message and same for success if (dsResult.Tables[0].Rows[0]["Message"] != null) acct.Message = Convert.ToString(dsResult.Tables[0].Rows[0]["Message"]); if (dsResult.Tables[0].Rows[0]["Success"] != null) acct.Success = Convert.ToBoolean(dsResult.Tables[0].Rows[0]["Success"]); return acct; }