Beispiel #1
0
        public void loadAllProducts()
        {
            try
            {
                ProductLazy    productLazy = new ProductLazy();
                List <Product> allOfDem    = productLazy.loadAllProducts();
                allProductList = new ObservableCollection <Product>();
                foreach (Product prod in allOfDem)
                {
                    if (!productList.Contains(prod))
                    {
                        allProductList.Add(prod);
                    }
                }

                List <ExpandoObject> productListView = new List <ExpandoObject>();
                foreach (Product product in allProductList)
                {
                    dynamic javascript = new ExpandoObject();
                    javascript.Name    = product.Name;
                    javascript.InStock = product.InStock ? "Yes" : "No";
                    javascript.Guid    = product.GUID;
                    productListView.Add(javascript);
                }

                lvAllProducts.ItemsSource = productListView;
            }
            catch (Exception exception)
            {
                ErrorHandler.ErrorHandle error = ErrorHandler.ErrorHandle.getInstance();
                error.handle(exception, true, true);
            }
        }
Beispiel #2
0
        public void updateView(Guid guid)
        {
            try
            {
                ProductLazy productLazy = new ProductLazy(guid);
                productList = new ObservableCollection <Product>(productLazy.ProductList);


                List <ExpandoObject> productListView = new List <ExpandoObject>();
                foreach (Product product in productList)
                {
                    dynamic javascript = new ExpandoObject();
                    javascript.Name    = product.Name;
                    javascript.InStock = product.InStock ? "Yes" : "No";
                    javascript.Guid    = product.GUID;
                    productListView.Add(javascript);
                }

                lvOptionProducts.ItemsSource = productListView;

                updateOptionCost();
            }
            catch (Exception exception)
            {
                ErrorHandler.ErrorHandle error = ErrorHandler.ErrorHandle.getInstance();
                error.handle(exception, true, true);
            }
        }
        public void NestedSessionScopeAndLazyLoad()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(ProductLazy), typeof(CategoryLazy));
            Recreate();

            ProductLazy product = new ProductLazy();

            product.Categories.Add(new CategoryLazy("x"));
            product.Categories.Add(new CategoryLazy("y"));
            product.Categories.Add(new CategoryLazy("z"));

            foreach (CategoryLazy cat in product.Categories)
            {
                cat.Save();
            }

            product.Save();

            using (new SessionScope())
            {
                ProductLazy product1 = ProductLazy.Find(product.Id);
                Assert.AreEqual(3, product1.Categories.Count);

                foreach (CategoryLazy cat in product1.Categories)
                {
                    object dummy = cat.Name;
                }

                ProductLazy product2 = ProductLazy.Find(product.Id);
                Assert.AreEqual(3, product2.Categories.Count);

                using (new SessionScope())
                {
                    foreach (CategoryLazy cat in product2.Categories)
                    {
                        object dummy = cat.Name;
                    }
                }

                using (new SessionScope())
                {
                    ProductLazy product3 = ProductLazy.Find(product.Id);
                    Assert.AreEqual(3, product3.Categories.Count);

                    foreach (CategoryLazy cat in product3.Categories)
                    {
                        object dummy = cat.Name;
                    }
                }
            }
        }