/// <summary> /// Method to search through all <c>Customer</c> objects /// </summary> /// <returns> /// A list of <c>Customer</c> objects from the database. If not found, returns null /// </returns> public List <Customer> CustomerSearch() { newCustomer = new Customer(); newCustomer.FirstName = InputPrompts.FirstNamePrompt(); newCustomer.LastName = InputPrompts.LastNamePrompt(); var dbCustomerSearch = db.Customers.Where(x => x.FirstName == newCustomer.FirstName && x.LastName == newCustomer.LastName).ToList(); return(dbCustomerSearch); }
/// <summary> /// The method to add customer records /// Runs through prompt to gather and validate customer info /// </summary> /// <returns> /// A <c>Customer</c> object containing the new customer info /// </returns> public Customer AddCustomer() { newCustomer = new Customer(); //While true loops used to control the data prompting - Thanks @Will Ruiz for the idea! //Does not break until input is validated //uses Regex patterns to validate the inputs //Pattens contained in Regex pattern class #region Customer Input Prompts try { newCustomer.FirstName = InputPrompts.FirstNamePrompt(); newCustomer.LastName = InputPrompts.LastNamePrompt(); newCustomer.AddressLine1 = InputPrompts.Address1Prompt(); newCustomer.AddressLine2 = InputPrompts.Address2Prompt(); newCustomer.City = InputPrompts.CityPrompt(); newCustomer.State = InputPrompts.StatePrompt(); newCustomer.ZipCode = InputPrompts.ZipPrompt(); newCustomer.Phone = InputPrompts.PhonePrompt(); newCustomer.Email = InputPrompts.EmailPrompt(); } catch (System.Exception e) { Console.WriteLine($"Error inputting customer information:\n{e}."); } #endregion //Print out the information that was input for confirmation newCustomer.PrintInfo(); //Do loop to prompt for confirmation. If confirmed, data is stored to the database as a new customer do { Console.WriteLine("Create new customer with this new information?"); Console.WriteLine("Press Y to confirm"); Console.WriteLine("Press N to reinput information"); Console.WriteLine("Press C to cancel"); //Using this readkey object to manage navigation response = Console.ReadKey(false).Key; if (response == ConsoleKey.Y) { //If confirmed, add the customer to the database Console.WriteLine(); db.Add(newCustomer); db.SaveChanges(); return(newCustomer); } if (response == ConsoleKey.N) { //Recall the method to reinput the customer information Console.WriteLine(); return(this.AddCustomer()); } if (response == ConsoleKey.C) { //break the loop to cancel the customer creation break; } } while (response != ConsoleKey.Y && response != ConsoleKey.N && response != ConsoleKey.C); return(null); }