feat: addded authorById

This commit is contained in:
SkajpCZ 2025-11-10 10:32:32 +01:00
parent 9398c1a6de
commit 17f4c10602

View File

@ -213,6 +213,41 @@ public class Team4
}
}
public static AuthorDto GetAuthorById(SqliteConnection conn, int authorID)
{
try
{
using (var command = conn.CreateCommand())
{
command.CommandText = @"
SELECT author.ID
FROM Authors author
WHERE author.ID = @aid;";
command.Parameters.AddWithValue("@aid", authorID);
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
return new AuthorDto
{
Id = reader.GetInt32(0),
Name = reader.GetString(1),
Surname = reader.GetString(2),
DateOfBirth = reader.GetDateTime(3)
};
}
}
return null;
}
}
catch (Exception ex)
{
Console.WriteLine($"Error in GetAuthorById: {ex.Message}");
throw;
}
}
public static void GetBooksBy(SqliteConnection conn)
{
throw new NotImplementedException();