Exemplo n.º 1
0
        public static void DeleteCustomer(NorthwindEntities db, string customerId)
        {
            Console.WriteLine("DELETING CUSTOMER...");
            var customer = db.Customers.FirstOrDefault(x => x.CustomerID.ToLower() == customerId.ToLower());
            if (customer != null)
            {
                var orders = db.Orders.Where(x => x.CustomerID.ToLower() == customerId.ToLower()).ToList();
                foreach (var order in orders)
                {
                    order.CustomerID = null;
                }

                db.SaveChanges();

                db.Customers.Remove(customer);
                db.SaveChanges();
            }

            Console.WriteLine("DONE");
        }
Exemplo n.º 2
0
        public static void ModifyCustomer(NorthwindEntities db, string customerId, Action<Customer> operation)
        {
            Console.WriteLine("MODIFYING CUSTOMER...");
            Customer customer = db.Customers.FirstOrDefault(x => x.CustomerID.ToLower() == customerId.ToLower());
            if (customer != null)
            {
                operation.Invoke(customer);
                db.SaveChanges();
            }

            Console.WriteLine("DONE");
        }
Exemplo n.º 3
0
        public static void InsertCustomer(NorthwindEntities db, Customer customer)
        {
            Console.WriteLine("INSERTING CUSTOMER...");
            var allCustomers = db.Customers;
            foreach (var item in allCustomers)
            {
                if (item.CustomerID.ToLower() == customer.CustomerID.ToLower())
                {
                    return;
                }
            }

            db.Customers.Add(customer);
            db.SaveChanges();
            Console.WriteLine("DONE");
        }