/** * @author Anthony Scheeres */ internal bool getPermissionFromDatabaseByTokenHasAdmin(string token) { var sqlQueryForRegistingUser = "******"; using var connectionWithDatabase = ConnectionProvider.getProvide(); connectionWithDatabase.Open(); //open the connection using var command = new NpgsqlCommand(sqlQueryForRegistingUser, connectionWithDatabase); command.Parameters.AddWithValue("token", token); command.Prepare(); //Construct and optimize query var i = command.ExecuteReader(); bool areTheseCredentialsValid = false; PsqlUtilities.GetAll(i).ForEach(r => { Console.WriteLine(r.GetValue(0).ToString()); if (r.GetValue(0).ToString().ToLower() == "true") { areTheseCredentialsValid = true; } }); connectionWithDatabase.Close(); //close the connection to save bandwith return(areTheseCredentialsValid); }
internal string getTokenByUsernameExtremelyClassified(double id) { var sqlQueryForRegistingUser = "******"; using var connectionWithDatabase = ConnectionProvider.getProvide(); connectionWithDatabase.Open(); //open the connection using var command = new NpgsqlCommand(sqlQueryForRegistingUser, connectionWithDatabase); command.Parameters.AddWithValue("id", id); command.Prepare(); //Construct and optimize query var i = command.ExecuteReader(); string hasAdmin = ""; PsqlUtilities.GetAll(i).ForEach(r => { Console.WriteLine(r.GetValue(0).ToString()); if (r.GetValue(0).ToString().Length >= 1) { hasAdmin = r.GetValue(0).ToString(); } }); connectionWithDatabase.Close(); //close the connection to save bandwith return(hasAdmin); }
private double TokenToUserIdn(string token) { var sqlQueryForRegistingUser = "******"; using var connectionWithDatabase = ConnectionProvider.getProvide(); connectionWithDatabase.Open(); //open the connection using var command = new NpgsqlCommand(sqlQueryForRegistingUser, connectionWithDatabase); command.Parameters.AddWithValue("token", token); command.Prepare(); //Construct and optimize query var i = command.ExecuteReader(); int id = 0; PsqlUtilities.GetAll(i).ForEach(r => { Console.WriteLine(r.GetValue(0).ToString()); if (ValidateInputUtilities.isNumeric(r.GetValue(0).ToString())) { id = int.Parse(r.GetValue(0).ToString()); } }); connectionWithDatabase.Close(); //close the connection to save bandwith return(id); }
/** * @author Anthony Scheeres */ internal bool checkUsernameAndToken(string token, string username) { const string sqlQueryForRegistingUser = "******"; var connectionWithDatabase = _connection; connectionWithDatabase.Open(); //open the connection using var command = new NpgsqlCommand(sqlQueryForRegistingUser, connectionWithDatabase); command.Parameters.AddWithValue("username", username); command.Parameters.AddWithValue("token", token); command.Prepare(); //Construct and optimize query var i = command.ExecuteReader(); bool areTheseCredentialsValid = false; PsqlUtilities.GetAll(i).ForEach(r => { Console.WriteLine(r.GetValue(0).ToString()); if (r.GetValue(0).ToString().ToLower() == "true") { areTheseCredentialsValid = true; } }); connectionWithDatabase.Close(); //close the connection to save bandwith return(areTheseCredentialsValid); }
/** * @author Anthony Scheeres */ private string getEmailUsingToken(string token) { var sqlQueryForRegistingUser = "******"; var connectionWithDatabase = _connection; connectionWithDatabase.Open(); //open the connection using var command = new NpgsqlCommand(sqlQueryForRegistingUser, connectionWithDatabase); command.Parameters.AddWithValue("token", token); command.Prepare(); //Construct and optimize query string emailToReturn = ""; var i = command.ExecuteReader(); PsqlUtilities.GetAll(i).ForEach(r => { Console.WriteLine(r.GetValue(0).ToString()); if (r.GetValue(0).ToString().Length >= 1) { emailToReturn = r.GetValue(0).ToString(); } }); connectionWithDatabase.Close(); //close the connection to save bandwith return(emailToReturn); }
internal bool CheckOverlappingDatesInDatabase(DateTime time_from, DateTime time_till, int kamerId) { const string query = "select exists (select * from reservations where roomno=@roomno and time_till::timestamp::date <= @time_till ::date and @time_from::date <= time_from::timestamp::date)"; var connectionWithDatabase = _connection; connectionWithDatabase.Open(); //open the connection using var command = new NpgsqlCommand(query, connectionWithDatabase); var typpe = "yyyy-MM-dd"; command.Parameters.AddWithValue("time_till", time_till.ToString(typpe)); command.Parameters.AddWithValue("time_from", time_from.ToString(typpe)); command.Parameters.AddWithValue("roomno", kamerId); command.Prepare(); //Construct and optimize query var i = command.ExecuteReader(); bool credentialsAreValid = false; // int index = (i.GetOrdinal("exists")); PsqlUtilities.GetAll(i).ForEach(r => { if (r.GetValue(0).ToString().ToLower() == "true") { credentialsAreValid = true; } }); connectionWithDatabase.Close(); //close the connection to save bandwith return(credentialsAreValid); }
/** * @author Anthony Scheeres */ internal bool checkUsernameAndPassword(string password, string username) { const string sqlQueryForRegistingUser = "******"; using var connectionWithDatabase = ConnectionProvider.getProvide(); connectionWithDatabase.Open(); //open the connection using var command = new NpgsqlCommand(sqlQueryForRegistingUser, connectionWithDatabase); command.Parameters.AddWithValue("username", username); command.Parameters.AddWithValue("password", password); command.Prepare(); //Construct and optimize query var i = command.ExecuteReader(); bool credentialsAreValid = false; string columnName = "exists"; // int index = (i.GetOrdinal("exists")); PsqlUtilities.GetAll(i).ForEach(r => { Console.WriteLine(r.GetValue(0).ToString()); if (r.GetValue(0).ToString().ToLower() == "true") { credentialsAreValid = true; } }); connectionWithDatabase.Close(); //close the connection to save bandwith return(credentialsAreValid); }