public void Createuser(userDAO userToCreate) { try { using (SqlConnection _connection = new SqlConnection(connectionstring)) { using (SqlCommand _command = new SqlCommand("Sp_CreateUser", _connection)) { _command.CommandType = CommandType.StoredProcedure; _command.Parameters.AddWithValue("@Username", userToCreate.Username); _command.Parameters.AddWithValue("@Password", userToCreate.Password); _command.Parameters.AddWithValue("@Role_ID", userToCreate.Role_ID); _connection.Open(); _command.ExecuteNonQuery(); _connection.Close(); _connection.Dispose(); } } } catch (Exception _Error) { Error_Logger Log = new Error_Logger(); Log.Errorlogger(_Error); } }
public List <userDAO> GetAllUsers() { List <userDAO> _userlist = new List <userDAO>(); try { using (SqlConnection _connection = new SqlConnection(connectionstring)) { using (SqlCommand _command = new SqlCommand("Sp_ViewUsers", _connection)) { _command.CommandType = CommandType.StoredProcedure; _connection.Open(); using (SqlDataReader _reader = _command.ExecuteReader()) { while (_reader.Read()) { userDAO _userToList = new userDAO(); _userToList.User_ID = _reader.GetInt32(0); _userToList.Username = _reader.GetString(1); _userToList.Password = _reader.GetString(2); _userToList.Role_ID = _reader.GetInt32(3); _userlist.Add(_userToList); } } } } } catch (Exception _Error) { Error_Logger Log = new Error_Logger(); Log.Errorlogger(_Error); } return(_userlist); }
public bool DeleteUser(userDAO userToDelete) { bool yes = false; try { using (SqlConnection _connection = new SqlConnection(connectionstring)) { using (SqlCommand _command = new SqlCommand("Sp_DeleteUser", _connection)) { _command.CommandType = CommandType.StoredProcedure; _command.Parameters.AddWithValue("@User_ID", userToDelete.User_ID); _connection.Open(); _command.ExecuteNonQuery(); yes = true; _connection.Close(); } } } catch (Exception _Error) { Error_Logger Log = new Error_Logger(); Log.Errorlogger(_Error); } if (yes == true) { } return(yes); }
public userDAO CreateShoppingCartOnRegister1(userDAO shoppingCartFromRegister1) { try { using (SqlConnection _connection = new SqlConnection(connectionstring)) { using (SqlCommand _command = new SqlCommand("Sp_CreateCartOnRegisterPart1", _connection)) { _command.CommandType = CommandType.StoredProcedure; _command.Parameters.AddWithValue("Username", shoppingCartFromRegister1.Username); using (SqlDataReader _reader = _command.ExecuteReader()) { while (_reader.Read()) { userDAO _dataToRead = new userDAO(); _dataToRead.User_ID = _reader.GetInt32(0); _dataToRead.Username = _reader.GetString(1); _dataToRead.Password = _reader.GetString(2); _dataToRead.Role_ID = _reader.GetInt32(3); shoppingCartFromRegister1 = _dataToRead; } } } } } catch (Exception _Error) { Error_Logger Log = new Error_Logger(); Log.Errorlogger(_Error); } return(shoppingCartFromRegister1); }
public userDAO Login(userDAO _userLogin) { try { using (SqlConnection _connection = new SqlConnection(connectionstring)) { using (SqlCommand _command = new SqlCommand("Sp_UserLogin", _connection)) { _command.CommandType = CommandType.StoredProcedure; _command.Parameters.AddWithValue("@Username", _userLogin.Username); _command.Parameters.AddWithValue("@Password", _userLogin.Password); _connection.Open(); _command.ExecuteNonQuery(); using (SqlDataReader _reader = _command.ExecuteReader()) { while (_reader.Read()) { userDAO _userToView = new userDAO(); _userToView.User_ID = _reader.GetInt32(0); _userToView.Username = _reader.GetString(1); _userToView.Password = _reader.GetString(2); _userToView.Role_ID = _reader.GetInt32(3); _userLogin = _userToView; } } _connection.Close(); _connection.Dispose(); } } } catch (Exception errorCaught) { Error_Logger LogError = new Error_Logger(); LogError.Errorlogger(errorCaught); } return(_userLogin); }