Exemple #1
0
        public static void Run()
        {
            // Initialize customer factory
            _customerFactory = new CustomerFactory();
            Console.WriteLine("NHibernate test started");

            Console.WriteLine("Loading customers into the cache...");

            // Load customers into the cache
            _customerFactory.GetCustomers();
            _customerFactory.SessionDisconnect();
            Console.WriteLine("Customers information loaded in the cache");

            // Prints the customers in the cache
            PrintCustomerList(_customerFactory.GetCustomers());

            Random randGen = new Random();
            int    randNum = randGen.Next(0, 9);
            string id      = GetCustomerId(randNum);

            // Adds a new customer with randomId
            _customerFactory.SaveCustomer(GenerateCustomer(true, id));

            // Prints the customer details
            PrintCustomerDetail(_customerFactory.GetCustomer(id));

            // Fetches the customer Orders
            Customer customer = _customerFactory.GetCustomerOrders(id);

            PrintCustomerOrders(customer);

            // Updates the customer
            Customer tempCust = GenerateCustomer(false, id);

            if (tempCust != null)
            {
                _customerFactory.UpdateCustomer(tempCust);
            }

            // Deletes the customer
            _customerFactory.RemoveCustomer(id);

            // Disconnect session
            _customerFactory.SessionDisconnect();

            // Dispose customer factory once done
            _customerFactory.Dispose();
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            try
            {
                // Initialize customer factory
                cf = new CustomerFactory();
                Console.WriteLine("NHibernate test started");

                Console.WriteLine("Loading customers into the cache...");

                cf.GetCustomers();
                cf.SessionDisconnect();
                Console.WriteLine("Customers information loaded in the cache");


                int choice = 0;
                while (choice != 7)
                {
                    choice = GetUserChoice();
                    string id;
                    try
                    {
                        switch (choice)
                        {
                        case 1:
                            PrintCustomerList(cf.GetCustomers());
                            cf.SessionDisconnect();
                            break;

                        case 2:
                            id = GetCustomerId();
                            PrintCustomerDetail(cf.GetCustomer(id));
                            cf.SessionDisconnect();
                            break;

                        case 3:
                            id = GetCustomerId();
                            Customer customer = cf.GetCustomerOrders(id);
                            PrintCustomerOrders(customer);
                            cf.SessionDisconnect();
                            break;

                        case 4:
                            id = GetCustomerId();
                            cf.RemoveCustomer(id);
                            cf.SessionDisconnect();
                            break;

                        case 5:
                            cf.SaveCustomer(AddCustomer(true));
                            cf.SessionDisconnect();
                            break;

                        case 6:
                            Customer tempCust = AddCustomer(false);
                            if (tempCust != null)
                            {
                                cf.UpdateCustomer(tempCust);
                                cf.SessionDisconnect();
                            }
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("\n" + ex + "\n");
                        Console.Read();
                    }
                }
                cf.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error:" + e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine(e.InnerException.Message);
                }
                Console.Read();
            }
        }