diff --git a/LoggingClient/LoggingClient/Repository/CustomerRepository.cs b/LoggingClient/LoggingClient/Repository/CustomerRepository.cs index 54d03a7..83ae162 100755 --- a/LoggingClient/LoggingClient/Repository/CustomerRepository.cs +++ b/LoggingClient/LoggingClient/Repository/CustomerRepository.cs @@ -1,5 +1,8 @@ using LoggingClient.Model; +using MySql.Data.MySqlClient; +using System; using System.Collections.Generic; +using System.Windows; namespace LoggingClient.Repository { @@ -7,16 +10,19 @@ namespace LoggingClient.Repository { public CustomerRepository(string connectionString) : base(connectionString) { - + Customers = new List(); } - public override string TableName => throw new System.NotImplementedException(); + public override string TableName => "customer"; - public override string ColumnsForSelect => throw new System.NotImplementedException(); + public override string ColumnsForSelect => "customer_id, firstname, lastname, customernumber, kundenkonto_fk, tel, email, url, password"; - public override string ColumnsForAdd => throw new System.NotImplementedException(); + public override string ColumnsForAdd => "firstname, lastname, customernumber, kundenkonto_fk, tel, email, url, password"; - public override string PrimaryKeyFromTable => throw new System.NotImplementedException(); + public override string PrimaryKeyFromTable => "customer_id"; + + public List Customers { get; set; } + public Customer _Customers { get; set; } public override void Add(Customer entity) { @@ -40,7 +46,37 @@ namespace LoggingClient.Repository public override List GetAll() { - throw new System.NotImplementedException(); + try + { + using (var conn = new MySqlConnection(ConnectionString)) + { + conn.Open(); + using (MySqlCommand cmd = conn.CreateCommand()) + { + cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName}"; + var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + Customers.Add(new Customer( + reader.GetInt32("customer_id"), + reader.GetValue(reader.GetOrdinal("firstname")) as string, + reader.GetValue(reader.GetOrdinal("lastname")) as string, + reader.GetValue(reader.GetOrdinal("customernumber")) as string, + reader.GetInt32("kundenkonto_fk"), + reader.GetValue(reader.GetOrdinal("tel")) as string, + reader.GetValue(reader.GetOrdinal("email")) as string, + reader.GetValue(reader.GetOrdinal("url")) as string, + reader.GetValue(reader.GetOrdinal("password")) as string + )); + } + } + } + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } + return Customers; } public override Customer GetSingle

(P pkValue)