Example #1
0
        static void Main(string[] args)
        {
            var customer        = new Customer();
            var customerManager = new CustomerManager();

            var customers       = new List <Customer>();
            var defaultCustomer = new Customer
            {
                Name      = "İsmail",
                Surname   = "Gümüş",
                Age       = 37,
                City      = "Ankara",
                IsDeleted = false,
                Id        = 1
            };

            customers.Add(defaultCustomer);

            Console.WriteLine("1. Müşteri Ekle");
            Console.WriteLine("2. Müşteri Sil");
            Console.WriteLine("3. Müşteri Güncelle");
            Console.WriteLine("Yapmak istediğiniz işlemi seçiniz:");
            var operation = Convert.ToInt32(Console.ReadLine());

            switch (operation)
            {
            case 1:
                Console.WriteLine("Müşteri Adı:");
                customer.Name = Console.ReadLine();
                Console.WriteLine("Müşteri Soyadı:");
                customer.Surname = Console.ReadLine();
                Console.WriteLine("Müşteri Şehri:");
                customer.City = Console.ReadLine();
                Console.WriteLine("Müşteri Yaşı:");
                customer.Age = Convert.ToInt32(Console.ReadLine());
                customerManager.Add(customer);
                break;

            case 2:
                customerManager.ListAll(customers);
                Console.WriteLine("Silmek istediğiniz müşteriyi id'sini seçiniz:");
                var selectedCustomer = Convert.ToInt32(Console.ReadLine());
                customer = customers.FirstOrDefault(x => x.Id == selectedCustomer);
                customerManager.Delete(customer);
                break;

            case 3:
                customerManager.ListAll(customers);
                Console.WriteLine("Güncellemek istediğiniz müşteriyi id'sini seçiniz:");
                selectedCustomer = Convert.ToInt32(Console.ReadLine());
                customer         = customers.FirstOrDefault(x => x.Id == selectedCustomer);
                customerManager.Update(customer);
                break;
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Customer customer1 = new Customer();

            customer1.Id      = 1;
            customer1.Name    = "Ali";
            customer1.Surname = "ARMUT";
            customer1.Age     = 32;
            customer1.TC      = "12345678911";

            Customer customer2 = new Customer();

            customer2.Id      = 2;
            customer2.Name    = "Emel";
            customer2.Surname = "ELMA";
            customer2.Age     = 25;
            customer2.TC      = "12345678912";

            Customer customer3 = new Customer();

            customer3.Id      = 3;
            customer3.Name    = "Kemal";
            customer3.Surname = "KİRAZ";
            customer3.Age     = 38;
            customer3.TC      = "12345678913";

            Customer customer4 = new Customer();

            customer4.Id      = 4;
            customer4.Name    = "Pelin";
            customer4.Surname = "PORTAKAL";
            customer4.Age     = 29;
            customer4.TC      = "12345678914";

            CustomerManager customerManager = new CustomerManager();

            customerManager.Add(customer1);
            customerManager.Add(customer2);
            customerManager.Add(customer3);
            customerManager.Add(customer4);

            Customer[] customers = new Customer[] { customer1, customer2, customer3, customer4 };
            Console.WriteLine("Müşteri Listesi");
            Console.WriteLine("Sıra -- İsim -- Soyisim  -- Yaş -- TC Numarası");
            foreach (var customer in customers)
            {
                customerManager.ListAll(customer);
            }
            Console.WriteLine("**************************************");

            customerManager.Delete(customer1);
            customerManager.Delete(customer2);
            customerManager.Delete(customer3);
            customerManager.Delete(customer4);
        }
        static void Main(string[] args)
        {
            #region customers
            Customer customer1 = new Customer(1000001, "John", "Foley", true);

            Customer customer2 = new Customer(1000002, "Lacy", "Evans", false);

            Customer customer3 = new Customer(1000003, "Victor", "Oladipo", true);

            Customer customer4 = new Customer(1000004, "Blake", "Manning", false);

            Customer[] allCustomers = new Customer[] { customer1, customer2, customer3, customer4 };
            #endregion

            CustomerManager customerManager = new CustomerManager();

            #region yaz-customers
            foreach (var x in allCustomers)
            {
                customerManager.Add(x);
                Console.WriteLine("--------");
            }

            Console.WriteLine("Non-Retired Customers: \n__");

            for (int j = 0; j < allCustomers.Length; j++)
            {
                if (allCustomers[j].Working == true)
                {
                    customerManager.ListAll(allCustomers[j]);
                    Console.WriteLine("*");
                }
            }
            #endregion


            start : Console.WriteLine("Please choose one of the following: \r\n 1. Update a customer \r\n 2. Delete a customer");
            string o1 = null;
            o1 = Console.ReadLine();

            switch (o1)
            {
                #region case 1
            case "1":
                Console.WriteLine("Please enter an ID Code: ");
                int enteredNumber = new int();
                enteredNumber = int.Parse(Console.ReadLine());
                for (int a = 0; a < allCustomers.Length; a++)
                {
                    if (enteredNumber == allCustomers[a].Id)
                    {
                        Console.WriteLine("Found : {0} {1}", allCustomers[a].Name, allCustomers[a].Surname);
                        Console.WriteLine("Please enter a new name: ");
                        allCustomers[a].Name = Console.ReadLine().ToString();
                        Console.WriteLine("You have successfully changed name.");
                        goto start;
                    }
                }
                Console.WriteLine("Couldn't find the ID you have entered : {0}", enteredNumber);
                goto start;

                #endregion
                #region case 2
            case "2":
                Console.WriteLine("Please enter an ID Code: ");
                int enteredNumber2 = new int();
                enteredNumber2 = int.Parse(Console.ReadLine());
                for (int i = 0; i < allCustomers.Length; i++)
                {
                    if (enteredNumber2 == allCustomers[i].Id)
                    {
                        yesorno : Console.WriteLine("Are you sure to delete " + allCustomers[i].Name + " " + allCustomers[i].Surname + "?" + "Y/N");
                        string yes = "Y";
                        string no  = "N";
                        string o2  = null;
                        o2 = Console.ReadLine();
                        if (o2 == yes || o2 == no)
                        {
                            switch (o2)
                            {
                            case "Y":
                                customerManager.Delete(allCustomers[i]);
                                goto start;

                            case "N":
                                Console.WriteLine(allCustomers[i].Name + allCustomers[i].Surname + "will not be deleted.");
                                goto start;
                            }
                        }
                        Console.WriteLine("Please use either Y or N.");
                        goto yesorno;
                    }
                }
                Console.WriteLine("You have entered an invalid ID code.");
                goto start;
                #endregion
            }
        }