Ejemplo n.º 1
0
        internal void ShowEnteringCustomer()
        {
            _service  = new CustomerService();
            _customer = new Customer();
            Console.Write("Name: ");
            _customer.Name = Console.ReadLine();

            while (true)
            {
                Console.Write("Email Office: ");
                _customer.EmailOffice = Console.ReadLine();
                if (_service.IsValidEmail(_customer.EmailOffice))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid email address, please input again");
                }
            }
            while (true)
            {
                try
                {
                    Console.Write("Phone Office: ");
                    _customer.PhoneOffice = Convert.ToInt32(Console.ReadLine());
                    break;
                }
                catch
                {
                    Console.WriteLine("Invalid phone number, please input again");
                }
            }
            while (true)
            {
                Console.Write("Email Home: ");
                _customer.EmailHome = Console.ReadLine();
                if (_service.IsValidEmail(_customer.EmailHome))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid email address, please input again");
                }
            }

            while (true)
            {
                try
                {
                    Console.Write("Phone Home: ");
                    _customer.PhoneHome = Convert.ToInt32(Console.ReadLine());
                    break;
                }
                catch
                {
                    Console.WriteLine("Invalid phone number, please input again");
                }
            }
        }
Ejemplo n.º 2
0
        static int Main(string[] args)
        {
            var ui    = new UserInterface();
            var logic = new CustomerService();

            while (true)
            {
                ui.ShowMainMenu();
                int selectedItem = ui.GetEnteringInputNumber();

                switch (selectedItem)
                {
                case 1:     //Add new customer
                    ui.ShowEnteringCustomer();
                    var newCustomer = ui.GetEnteringCustomer();
                    var result      = logic.Save(newCustomer);
                    ui.Inform(result.Message);
                    break;

                case 2:     //Edit a customer
                    ui.ShowEnteringId("Input id to edit customer: ");
                    int      idCustomerEdit = ui.GetEnteringInputNumber();
                    Customer editCustomer   = logic.GetCustomer(idCustomerEdit);
                    ui.ShowCustomer(editCustomer);
                    ui.Inform("===>Start update customer");
                    ui.ShowEnteringCustomer();
                    editCustomer = ui.GetEnteringCustomer();
                    if (logic.IsValidEmail(editCustomer.EmailHome) && logic.IsValidEmail(editCustomer.EmailOffice))
                    {
                        logic.Save(editCustomer);
                        ui.Inform("Updated!");
                    }
                    else
                    {
                        ui.Inform("Invalid email address!");
                    }
                    break;

                case 3:     //delete a customer
                    ui.ShowEnteringId("Input id to delete customer: ");
                    int customerId = ui.GetEnteringInputNumber();
                    var customer   = logic.GetCustomer(customerId);
                    if (customer != null)
                    {
                        if (ui.IsConfirmed())
                        {
                            logic.Delete(customer);
                            ui.Inform("Customer is deleted!");
                        }
                    }
                    else
                    {
                        ui.Inform("Invalid Customer Id!");
                    }
                    break;

                case 4:     //view customers
                    ui.ShowOptionViewCustomer();
                    int selectView = ui.GetEnteringInputNumber();
                    switch (selectView)
                    {
                    case 41:         //show all customers
                        List <Customer> customers = logic.GetCustomers();
                        ui.ShowAllCustomers(customers);
                        break;

                    case 42:         //show a customer
                        ui.ShowEnteringId("Input id to view customer: ");
                        int      idCustomerShow = ui.GetEnteringInputNumber();
                        Customer customerShow   = logic.GetCustomer(idCustomerShow);
                        if (customerShow != null)
                        {
                            ui.ShowCustomer(customerShow);
                        }
                        else
                        {
                            ui.Inform("Invalid Customer Id!");
                        }
                        break;
                    }
                    break;

                case 5:     //quit
                    return(0);

                default:
                    ui.Inform("Bad selection");
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        internal void ShowEnteringCustomer()
        {
            Console.WriteLine("\n===>Enter customer info:");
            _service  = new CustomerService();
            _customer = new Customer();

            while (true)
            {
                Console.Write("Name: ");
                _customer.Name = Console.ReadLine();
                if (_customer.Name.Replace(" ", "") != "")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Name is empry! Please input name again!");
                }
            }

            while (true)
            {
                Console.Write("Email Office: ");
                _customer.EmailOffice = Console.ReadLine();
                if (_service.IsValidEmail(_customer.EmailOffice))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid email address, please input again");
                }
            }
            while (true)
            {
                Console.Write("Phone Office: ");
                _customer.PhoneOffice = Console.ReadLine();
                if (_service.IsValidPhoneNumber(_customer.PhoneOffice))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid phone number, please input again");
                }
            }
            while (true)
            {
                Console.Write("Email Home: ");
                _customer.EmailHome = Console.ReadLine();
                if (_service.IsValidEmail(_customer.EmailHome))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid email address, please input again");
                }
            }

            while (true)
            {
                Console.Write("Phone Home: ");
                _customer.PhoneHome = Console.ReadLine();
                if (_service.IsValidPhoneNumber(_customer.PhoneHome))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid phone number, please input again");
                }
            }
        }