RetrieveAddress helper method

This commit is contained in:
Spudnut2000
2025-06-14 22:19:24 -05:00
parent b1609b1b1b
commit 6c6de5e505
3 changed files with 49 additions and 3 deletions

View File

@@ -115,4 +115,43 @@ public static class DatabaseHelper
throw;
}
}
public static Address? RetrieveAddress(int addressId)
{
using MySqlConnection connection = new MySqlConnection(AppSettings.GetSetting("ConnectionStrings", "DefaultConnection"));
try
{
connection.Open();
}
catch (MySqlException e)
{
Console.WriteLine(e);
throw;
}
string query = $"SELECT * FROM client_schedule.address WHERE addressId = {addressId}";
using MySqlCommand command = new MySqlCommand(query, connection);
using MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
var addr = new Address()
{
Id = reader.GetInt32("addressId"),
Address1 = reader.GetString("address1"),
Address2 = reader.GetString("address2"),
CityId = reader.GetInt32("cityId"),
PostalCode = reader.GetString("postalCode"),
Phone = reader.GetString("phone"),
CreateDate = reader.GetDateTime("createDate"),
CreatedBy = reader.GetString("createdBy"),
LastUpdate = reader.GetDateTime("lastUpdate"),
LastUpdateBy = reader.GetString("lastUpdateBy"),
};
return addr;
}
return null;
}
}