예제 #1
0
        private static void CustomerDetail()
        {
            CustomerManager customerManager = new CustomerManager(new EfCustomerDal());
            var             result          = customerManager.GetCustomer();

            Console.WriteLine("Sistemdeki kayıtlı müşteriler : \nMüşteri Numarası\t Şirket Adı");
            foreach (var customer in result.Data)
            {
                Console.WriteLine($"{customer.CustomerID}\t\t{customer.CompanyName}");
            }
        }
예제 #2
0
        private static void CustomerMenu(ConsoleKeyInfo key)
        {
            CustomerManager customerManager = new CustomerManager(new IMCustomerDAL(), new RealPersonCheckManager());

            ListCustomers(customerManager);

            Console.WriteLine("A - Add Customer");
            Console.WriteLine("U - Update Customer");
            Console.WriteLine("D - Delete Customer");
            Console.WriteLine("M - Main Menu");

            key = Console.ReadKey();

            switch (key.Key)
            {
            case ConsoleKey.A:
            {
                Console.WriteLine();
                Customer customer = new Customer();
                customer.Id = customerManager.GetAllCustomers().Max(x => x.Id) + 1;
                Console.Write("Customer FirstName : ");
                customer.FirstName = Console.ReadLine();
                Console.Write("Customer LastName : ");
                customer.LastName = Console.ReadLine();
                Console.Write("Customer NationalityId : ");
                customer.NationalityId = Console.ReadLine();
                Console.Write("Customer DateOfBirth : ");
                customer.DateOfBirth = Convert.ToDateTime(Console.ReadLine());
                Console.Write("Customer Favourite Genre : ");
                customer.FavouriteGenre = Console.ReadLine();

                try
                {
                    customerManager.AddCustomer(customer);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
                ListCustomers(customerManager);
            }
            break;

            case ConsoleKey.U:
            {
                Console.WriteLine();
                Customer customer = new Customer();
                Console.Write("Customer Id : ");

                if (int.TryParse(Console.ReadLine(), out int id))
                {
                    customer.Id = id;
                }
                if (customerManager.GetAllCustomers().SingleOrDefault(x => x.Id == customer.Id) != null)
                {
                    Console.Write("Favourite Genre : ");
                    customer.FavouriteGenre = Console.ReadLine();

                    customerManager.UpdateCustomer(customer);
                    ListCustomers(customerManager);
                }
                else
                {
                    Console.WriteLine("No such customer exists!!");
                }
            }
            break;

            case ConsoleKey.D:
            {
                Console.WriteLine();
                Console.Write("Customer Id : ");

                if (int.TryParse(Console.ReadLine(), out int id))
                {
                    var campaign = customerManager.GetCustomer(id);
                    if (campaign != null)
                    {
                        customerManager.DeleteCustomer(campaign);
                        ListCustomers(customerManager);
                    }
                }
                else
                {
                    Console.WriteLine("No such customer exists!!");
                }
            }
            break;

            case ConsoleKey.M:
            {
                Console.WriteLine("");
                MainMenu();
            }
            break;

            default:
                break;
            }
        }