public static void CreateCustomer() { Console.WriteLine("Enter first and last name (firstName lastName)"); string[] tokens = Console.ReadLine().Split(); string firstName = tokens[0].ToLower(); string lastName = tokens[1].ToLower(); try { if (firstName.Length < 1 || lastName.Length < 1) { throw new Exception("First and/or last name was empty."); } DataAccess.Model.Customer customer = new DataAccess.Model.Customer() { FirstName = firstName, LastName = lastName }; new CustomerRunner().AddCustomer(customer); } catch (Exception ex) { Console.WriteLine("Customer not created. Expected: (firstName lastName). " + ex.Message); } }
// Add customer to database void AddCustomer(DataAccess.Model.Customer cust) { if (cust == null) { throw new Exception("null cust"); } if (ProZeroRepo.DbContext == null) { throw new Exception("It's not good."); } ProZeroRepo.DbContext.Customer.Add(cust); Save(); }