public static void ShowForm() { CustomerController controller = new CustomerController(); CustomerDataAccess customer = new CustomerDataAccess(); AddressDataAccess address = new AddressDataAccess(); Console.Write("Customer First Name:\n"); customer.FirstName = Console.ReadLine(); Console.Write("Customer Last Name:\n"); customer.LastName = Console.ReadLine(); Console.Write("Address Line 1:\n"); address.Address1 = Console.ReadLine(); Console.Write("Address Line 2:\n"); address.Address2 = Console.ReadLine(); Console.Write("City:\n"); address.City = Console.ReadLine(); do { Console.Write("State: (2 letters)\n"); address.State = Console.ReadLine(); } while (address.State.Length != 2); Console.Write("ZipCode:\n"); address.Zipcode = Int32.Parse(Console.ReadLine()); customer.Addresses.Add(address); controller.Save(customer); Console.WriteLine("\nCustomer saved!\n"); Console.ReadKey(); ClearHelper.Clear(); }
public static void ShowForm() { Console.WriteLine("Fetching Data, please wait..."); AddressController controller = new AddressController(); //AddressDataAccess customer = new AddressDataAccess(); AddressesDataAccess address = new AddressesDataAccess(); CustomerController customerController = new CustomerController(); List <CustomerDataAccess> customersList = customerController.getAll(); CustomerDataAccess customer = null; int customerId = 0; do { ClearHelper.Clear(); Console.WriteLine("New Address\n"); //Show all customers foreach (CustomerDataAccess c in customersList) { Console.WriteLine(c.ToString()); } //Select Customer Console.WriteLine("\nSelect Customer to add address:\n"); customerId = Int32.Parse(Console.ReadLine()); customer = customerController.FindById(customerId); if (customer == null) { Console.WriteLine("\nWrong Customer Id"); Console.ReadKey(); } ClearHelper.Clear(); } while (customer == null); address.CustomerId = customerId; //New Address Console.WriteLine("New Address"); Console.WriteLine($"Customer: {customer.ToString()}\n"); Console.Write("Address Line 1:\n"); address.Address1 = Console.ReadLine(); Console.Write("Address Line 2:\n"); address.Address2 = Console.ReadLine(); Console.Write("City:\n"); address.City = Console.ReadLine(); do { Console.Write("State: (2 letters)\n"); address.State = Console.ReadLine(); } while (address.State.Length != 2); Console.Write("ZipCode:\n"); address.Zipcode = Int32.Parse(Console.ReadLine()); controller.Save(address); Console.WriteLine("\nAddress saved!\n"); Console.ReadKey(); ClearHelper.Clear(); }