wip
This commit is contained in:
@@ -25,14 +25,27 @@ namespace AppointmentsLib.Models
|
||||
{
|
||||
var reader = Database.Execute("SELECT appointmentId, contactId, time, description FROM Appointment;").ExecuteReader();
|
||||
|
||||
List<AppointmentData> data = new();
|
||||
List<Appointment> appointments = new();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
appointments.Add(new Appointment(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), reader.GetString(3)));
|
||||
data.Add(new AppointmentData()
|
||||
{
|
||||
AppointmentId = reader.GetInt32(0),
|
||||
ContactId = reader.GetInt32(1),
|
||||
Time = reader.GetString(2),
|
||||
Description = reader.GetString(3)
|
||||
});
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
|
||||
foreach (AppointmentData ad in data)
|
||||
{
|
||||
appointments.Add(ad.Finalize());
|
||||
}
|
||||
|
||||
return appointments;
|
||||
}
|
||||
|
||||
@@ -91,4 +104,17 @@ namespace AppointmentsLib.Models
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
internal class AppointmentData
|
||||
{
|
||||
public int AppointmentId;
|
||||
public int ContactId;
|
||||
public string Time;
|
||||
public string Description;
|
||||
|
||||
public Appointment Finalize()
|
||||
{
|
||||
return new Appointment(AppointmentId, ContactId, Time.ToString(), Description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,14 +52,34 @@ namespace AppointmentsLib.Models
|
||||
{
|
||||
var reader = Database.Execute($"SELECT {primaryKey}, {string.Join(", ", fields.ToArray())} FROM Contact;").ExecuteReader();
|
||||
|
||||
List<ContactData> data = new();
|
||||
List<Contact> contacts = new();
|
||||
|
||||
while (reader.Read())
|
||||
while(reader.Read())
|
||||
{
|
||||
contacts.Add(new Contact(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetInt32(4), reader.GetString(5), reader.GetInt32(6), reader.GetString(7), reader.GetInt32(8), reader.GetString(9)));
|
||||
data.Add(new ContactData()
|
||||
{
|
||||
ContactId = reader.GetInt32(0),
|
||||
SalutationId = reader.GetInt32(1),
|
||||
FirstName = reader.GetString(2),
|
||||
LastName = reader.GetString(3),
|
||||
Street = reader.GetString(4),
|
||||
PostalId = reader.GetInt32(5),
|
||||
Phone = reader.GetString(6),
|
||||
PhoneTypeId = reader.GetInt32(7),
|
||||
Mobil = reader.GetString(8),
|
||||
CompanyId = reader.GetInt32(9),
|
||||
Department = reader.GetString(10)
|
||||
});
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
|
||||
foreach (ContactData cd in data)
|
||||
{
|
||||
contacts.Add(cd.Finalize());
|
||||
}
|
||||
|
||||
return contacts;
|
||||
}
|
||||
|
||||
@@ -73,9 +93,24 @@ namespace AppointmentsLib.Models
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
var contact = new Contact(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetInt32(4), reader.GetString(5), reader.GetInt32(6), reader.GetString(7), reader.GetInt32(8), reader.GetString(9));
|
||||
var data = new ContactData()
|
||||
{
|
||||
ContactId = reader.GetInt32(0),
|
||||
SalutationId = reader.GetInt32(1),
|
||||
FirstName = reader.GetString(2),
|
||||
LastName = reader.GetString(3),
|
||||
Street = reader.GetString(4),
|
||||
PostalId = reader.GetInt32(5),
|
||||
Phone = reader.GetString(6),
|
||||
PhoneTypeId = reader.GetInt32(7),
|
||||
Mobil = reader.GetString(8),
|
||||
CompanyId = reader.GetInt32(9),
|
||||
Department = reader.GetString(10)
|
||||
};
|
||||
|
||||
reader.Close();
|
||||
return contact;
|
||||
|
||||
return data.Finalize();
|
||||
}
|
||||
|
||||
throw new Exception("contact does not exist");
|
||||
@@ -131,4 +166,24 @@ namespace AppointmentsLib.Models
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
internal class ContactData
|
||||
{
|
||||
public int ContactId;
|
||||
public int SalutationId;
|
||||
public string FirstName;
|
||||
public string LastName;
|
||||
public string Street;
|
||||
public int PostalId;
|
||||
public string Phone;
|
||||
public int PhoneTypeId;
|
||||
public string Mobil;
|
||||
public int CompanyId;
|
||||
public string Department;
|
||||
|
||||
public Contact Finalize()
|
||||
{
|
||||
return new Contact(ContactId, SalutationId, FirstName, LastName, Street, PostalId, Phone, PhoneTypeId, Mobil, CompanyId, Department);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user