From 17f4c10602a686a208861731b5692dada7015126 Mon Sep 17 00:00:00 2001 From: SkajpCZ <103284636+SkajpCZ@users.noreply.github.com> Date: Mon, 10 Nov 2025 10:32:32 +0100 Subject: [PATCH] feat: addded authorById --- src/team4.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/team4.cs b/src/team4.cs index 8f36e2f..2d86756 100644 --- a/src/team4.cs +++ b/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();