RetrieveAddress helper method
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user