diff --git a/src/team4.cs b/src/team4.cs index 299a9bc..c5e4a3f 100644 --- a/src/team4.cs +++ b/src/team4.cs @@ -250,6 +250,76 @@ namespace Team4 throw; } } + public static List> GetAuthorNameId(SqliteConnection conn) + { + try + { + using (var command = conn.CreateCommand()) + { + command.CommandText = @" + SELECT author.ID, author.Name, author.Surname + FROM Authors author"; + + var authors = new List>(); + + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + int id = reader.GetInt32(0); + string name = reader.IsDBNull(1) ? "" : reader.GetString(1); + string surname = reader.IsDBNull(2) ? "" : reader.GetString(2); + + authors.Add(new Dictionary + { + { id, new[] { name, surname } } + }); + } + } + return authors; + } + } + catch (Exception ex) + { + Console.WriteLine($"Error in GetAuthorNameId: {ex.Message}"); + throw; + } + } + + public static List> GetPublisherNameId(SqliteConnection conn) + { + try + { + using (var command = conn.CreateCommand()) + { + command.CommandText = @" + SELECT publisher.ID, publisher.Name + FROM Publisher publisher"; + + var publishers = new List>(); + + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + int id = reader.GetInt32(0); + string name = reader.IsDBNull(1) ? "" : reader.GetString(1); + + publishers.Add(new Dictionary + { + { id, name } + }); + } + } + return publishers; + } + } + catch (Exception ex) + { + Console.WriteLine($"Error in GetAuthorNameId: {ex.Message}"); + throw; + } + } public static void GetBooksBy(SqliteConnection conn) {