public static bool InsertOrders(List <Porder> orders) { bool inserted = false; int count = 0; foreach (Porder order in orders) { count = new Crud().AddOrder(order); if (count != 0) { inserted = true; } } List <Customer> customers = CustomerHandler.GetCustomers(); foreach (Customer customer in customers) { if (customer.PUserId != orders[0].PUserId) { inserted = CustomerHandler.AddCustomer(orders[0].PUserId); } } return(inserted); }
private void OkButton_OnClick(object sender, RoutedEventArgs e) { var customer = new Customer(NameTextBox.Text, ContactInfoTextBox.Text, NicTextBox.Text); if (NameTextBox.Text == "" || ContactInfoTextBox.Text == "" || !customer.IsNicValid()) { MessageBox.Show("Please make sure your inputs are valid"); return; } var customerHandler = new CustomerHandler(); try { customerHandler.AddCustomer(customer); MessageBox.Show("Customer added successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } Close(); }
///<summary>Adds customer information through user input and passes to handler class to validate and add to db</summary> public Customer AddNewCustomer() { Console.WriteLine("Enter First Name:"); string firstName = Console.ReadLine(); Console.WriteLine("Enter Last Name:"); string lastName = Console.ReadLine(); Console.WriteLine("Enter Street:"); string street = Console.ReadLine(); Console.WriteLine("Enter City:"); string city = Console.ReadLine(); Console.WriteLine("Enter State:"); string inputState = Console.ReadLine(); Console.WriteLine("Enter Zipcode:"); string zip = Console.ReadLine(); try { States state = (States)Enum.Parse(typeof(States), inputState, true); int zipcode = int.Parse(zip); Address custAddress = new Address() { Street = street, City = city, State = state, Zipcode = zipcode }; Customer c = new Customer() { FirstName = firstName, LastName = lastName, CustAddress = custAddress }; CustomerHandler ch = new CustomerHandler(); ch.AddCustomer(c); Console.WriteLine("Customer added!"); Log.Information($"Customer {firstName} {lastName} added"); return(c); } catch (CustomerException ex) { throw ex; } catch (ArgumentException e) { throw e; } catch (FormatException e) { throw e; } catch (InvalidAddressException e) { throw e; } }
public void SignupMenu() { //for new customers signing up CustomerHandler ch = new CustomerHandler(); ErrorHandler err = new ErrorHandler(); uname: Console.WriteLine("Enter Username: "******"Enter Password: "******"Enter First Name: "); string firstName = Console.ReadLine(); Console.WriteLine("Enter Last Name: "); string lastName = Console.ReadLine(); if (err.VerifyName(firstName, lastName) == false) { err.InvalidInputMsg(); goto name; } addin: Console.WriteLine("Enter Address: "); Console.WriteLine("Street: "); string street = Console.ReadLine(); Console.WriteLine("City: "); string city = Console.ReadLine(); Console.WriteLine("State: "); string state = Console.ReadLine(); Console.WriteLine("Zipcode: "); string zipcode = Console.ReadLine(); if (err.VerifyAddress(street, city, state, zipcode) == false) { err.InvalidInputMsg(); goto addin; } Address custAdd = new Address { Street = street, City = city, State = state, Zipcode = zipcode }; ch.AddCustomer(firstName, lastName, username, password, custAdd); Customer c = new Customer { FirstName = firstName, LastName = lastName, UserName = username, CustAddress = custAdd }; OrderMenu om = new OrderMenu(); om.Ordermenu(c); }