117 lines
3.5 KiB
C#
117 lines
3.5 KiB
C#
using Aufgabe14;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
Console.WriteLine("Willkommen zu Aufgabe14");
|
|
|
|
|
|
CustomerRepository customerRepository = new CustomerRepository(new ApplicationDbContext());
|
|
bool beenden = false;
|
|
int id;
|
|
|
|
while (!beenden)
|
|
{
|
|
Console.WriteLine("\n\nHauptmenü:");
|
|
Console.WriteLine("1 - Alle Datensätze anzeigen");
|
|
Console.WriteLine("2 - Neuen Datensatz hinzufügen");
|
|
Console.WriteLine("3 - Datensatz anzeigen (mit ID)");
|
|
Console.WriteLine("4 - Datensatz löschen (mit ID)");
|
|
Console.WriteLine("5 - Programm beenden");
|
|
Console.Write("Bitte wählen Sie eine Option: ");
|
|
|
|
string eingabe = Console.ReadLine();
|
|
|
|
switch (eingabe)
|
|
{
|
|
case "1":
|
|
foreach (Customer i in customerRepository.GetAll())
|
|
{
|
|
Ausgabe(i);
|
|
}
|
|
break;
|
|
|
|
case "2":
|
|
List<Customer> allCustomers = customerRepository.GetAll();
|
|
int highestId = allCustomers.Any() ? allCustomers.Max(c => c.Id) : 0;
|
|
|
|
Customer customer = new Customer();
|
|
|
|
customer.Id = highestId + 1;
|
|
Console.WriteLine($"Die neue Id: {customer.Id}");
|
|
|
|
Console.WriteLine("Firstname: ");
|
|
customer.Firstname = Console.ReadLine();
|
|
|
|
Console.WriteLine("Surname: ");
|
|
customer.Surname = Console.ReadLine();
|
|
|
|
Console.WriteLine("(0/1)Gender");
|
|
if (Console.ReadLine() == "0")
|
|
{
|
|
customer.Gender = Gender.Male;
|
|
}
|
|
else
|
|
{
|
|
customer.Gender = Gender.Female;
|
|
}
|
|
|
|
Console.WriteLine("City: ");
|
|
customer.Address.City = Console.ReadLine();
|
|
|
|
Console.WriteLine("Street: ");
|
|
customer.Address.Street = Console.ReadLine();
|
|
|
|
Console.WriteLine("(Number) StreetNumber: ");
|
|
customer.Address.StreetNumber = int.Parse(Console.ReadLine());
|
|
|
|
Console.WriteLine("PostCode: ");
|
|
customer.Address.PostCode = Console.ReadLine();
|
|
|
|
customerRepository.SaveOrUpdate(customer);
|
|
break;
|
|
|
|
case "3":
|
|
Console.WriteLine("Id: ");
|
|
eingabe = Console.ReadLine();
|
|
if (int.TryParse(eingabe, out id))
|
|
{
|
|
Ausgabe(customerRepository.Get(id));
|
|
}
|
|
break;
|
|
|
|
case "4":
|
|
Console.WriteLine("Id: ");
|
|
eingabe = Console.ReadLine();
|
|
if (int.TryParse(eingabe, out id))
|
|
{
|
|
customerRepository.Delete(customerRepository.Get(id));
|
|
}
|
|
break;
|
|
|
|
case "5":
|
|
Console.WriteLine("Programm wird beendet...");
|
|
Environment.Exit(0);
|
|
break;
|
|
|
|
default:
|
|
Console.WriteLine("Ungültige Eingabe, bitte versuchen Sie es erneut.");
|
|
break;
|
|
}
|
|
|
|
Console.WriteLine("Drücken Sie eine beliebige Taste, um fortzufahren...");
|
|
Console.ReadKey();
|
|
}
|
|
|
|
void Ausgabe(Customer customer)
|
|
{
|
|
if (customer != null)
|
|
{
|
|
Console.WriteLine($"Id: {customer.Id}");
|
|
Console.WriteLine($"Firstname: {customer.Firstname}");
|
|
Console.WriteLine($"Surname: {customer.Surname}");
|
|
Console.WriteLine($"Gender: {customer.Gender}");
|
|
Console.WriteLine($"City: {customer.Address.City}");
|
|
Console.WriteLine($"Street: {customer.Address.Street}");
|
|
Console.WriteLine($"StreetNumber: {customer.Address.StreetNumber}");
|
|
Console.WriteLine($"PostCode: {customer.Address.PostCode}");
|
|
}
|
|
} |