Esempio n. 1
0
        private void View_CategoryChanged(object sender, ProductListEventArgs e)
        {
            var category = e.Category;

            if (string.IsNullOrEmpty(category))
            {
                return;
            }

            var productsByCategory = this.View.Model.Products
                                     .Where(p => p.Category.Equals(category));

            this.View.Model.Products = productsByCategory;
        }
Esempio n. 2
0
        private void View_MyInit(object sender, ProductListEventArgs e)
        {
            var category = e.Category;

            IEnumerable <ProductDetailsViewModel> products;

            if (string.IsNullOrEmpty(category))
            {
                products = this.service.GetProducts()
                           .Select(p => this.factory.CreateProductDetailsViewModel(p.ProductId,
                                                                                   p.Name,
                                                                                   p.Category.Name,
                                                                                   p.Price,
                                                                                   p.Volume,
                                                                                   p.Maker,
                                                                                   p.ImageMimeType,
                                                                                   p.ImageBuffer));
            }
            else
            {
                products = this.service.GetProductsByCategory(category)
                           .Select(p => this.factory.CreateProductDetailsViewModel(p.ProductId,
                                                                                   p.Name,
                                                                                   p.Category.Name,
                                                                                   p.Price,
                                                                                   p.Volume,
                                                                                   p.Maker,
                                                                                   p.ImageMimeType,
                                                                                   p.ImageBuffer));
            }

            var categories = new List <string> {
                "All Products"
            };

            categories.AddRange(products.Select(p => p.Category).Distinct());

            this.View.Model.Products   = products;
            this.View.Model.Categories = categories;
        }