feat: addded authorById
This commit is contained in:
parent
9398c1a6de
commit
17f4c10602
35
src/team4.cs
35
src/team4.cs
@ -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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user