public void AddCustomerShouldAdd(string fullName) { //Arrange CustomerData customer = new CustomerData(); //Act Action act = () => customer.AddCustomerDB(fullName); //Assert Assert.Throws <IndexOutOfRangeException>(act); }
public ActionResult Create(IFormCollection collection) { try { // TODO: Add insert logic here var customers = new Customers { FirstName = collection["FirstName"], LastName = collection["LastName"] }; customerData.AddCustomerDB(customers); return(RedirectToAction(nameof(ListCustomers))); } catch { return(View()); } }
static void CustomersMenu() { CustomerData custData = new CustomerData(); int menuChoice; do { Console.Clear(); Console.WriteLine("1. Add Customer"); Console.WriteLine("2. View All Customers"); Console.WriteLine("3. Search Customer By Name"); Console.WriteLine("4+. Go Back"); Console.WriteLine("\nEnter Your Choice: "); menuChoice = Int32.Parse(Console.ReadLine()); Log.Information("Customer Menu Choice: {0}", menuChoice); switch (menuChoice) { case 1: Console.Clear(); string fullName; Console.WriteLine("Add Customer\n"); Console.WriteLine("Enter The Name: "); fullName = Console.ReadLine(); Log.Information("Added Customer: {0}", fullName); custData.AddCustomer(jsonFilePathCustomers, fullName); //SERIALIZED custData.AddCustomerDB(fullName); //DATABASE if (custData.nameHolder.Length == 2) { Console.WriteLine("Added Customer {0}", fullName); } else { Console.WriteLine("Invalid Name Entered"); } Console.WriteLine("Press Any Key To Continue: "); Console.ReadKey(); break; case 2: Console.Clear(); #region Serialized Data Output /*List<Customer> tempData = new List<Customer>(); * tempData = custData.DisplayCustomers(jsonFilePathCustomers); * * Console.Clear(); * Console.WriteLine("Customers"); * if (tempData.Count != 1) * { * for (int i = 0; i < tempData.Count; i++) * { * Console.WriteLine(" {0}. {1} {2}", i + 1, tempData[i].FirstName, tempData[i].LastName); * } * } * else * { * Console.WriteLine("No Data Present"); * }*/ #endregion CustomerData cust = new CustomerData(); cust.DisplayCustomersDB(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 3: Console.Clear(); string searchName; Console.WriteLine("Please Enter a First or a Last Name To Search"); searchName = Console.ReadLine(); #region SerializedSearching //List<Customer> tempDisplay = new List<Customer>(); //tempDisplay = custData.DisplayCustomers(jsonFilePathCustomers); //for (int i = 0; i < tempDisplay.Count; i++) //{ // if (tempDisplay[i].FirstName.Equals(searchName) || tempDisplay[i].LastName.Equals(searchName)) // { // Console.WriteLine(" {0}. {1} {2}", i + 1, tempDisplay[i].FirstName, tempDisplay[i].LastName); // } // else // { // custData.searchCount++; // } //} //if (custData.searchCount == tempDisplay.Count) //{ // Console.Clear(); // Console.WriteLine("No Such Record Present"); //} #endregion CustomerData customerData = new CustomerData(); customerData.SearchCustomersDB(searchName); Console.WriteLine("Press Any Key To Continue"); Console.ReadKey(); break; } } while (menuChoice < 4); }