Exemplo n.º 1
0
        public static ProductListModel Get(IRepository <Product> ProductRepository, IRepository <ProductCategory> ProductCategoryRepository)
        {
            var model = new ProductListModel
            {
                Products = ProductRepository.GetAll()
                           .OrderBy(u => u.ID)
                           .Select(u => new ListItem
                {
                    ID           = u.ID,
                    Name         = u.Name,
                    categoryName = ProductCategoryRepository.GetByID(u.categoryID).Name
                }).ToList()
            };

            return(model);

            //var products = ProductRepository.GetAll();
            //IEnumerable<ProductListModel> model = from a in ProductRepository.Query("SELECT * from Product")
            //                                      join b in ProductCategoryRepository.Query("SELECT * from ProductCategory") on a.categoryID equals b.ID
            //                                      select new ProductListModel()
            //                                      {
            //                                          Products = new Product(new ListItem { });
            //                                      };
            //var model = new ProductListModel
            //{
            //    Products = products.OrderBy(p => p.Name).Select(p => new ListItem
            //    {
            //        ID = p.ID,
            //        Name = p.Name,
            //        categoryNames = p.ProductInCategories.Select(x => x.ProductCategory.Name).ToList(),
            //    }).ToList()
            //};

            //return model;
        }
Exemplo n.º 2
0
        public static ProductListModel Get(IRepository <Product> ProductRepository)
        {
            var products = ProductRepository.GetAll().Result;
            var get      = products.Where(p => p.ID == 1)
                           .Select(pro => new
            {
                ID   = pro.ID,
                Name = pro.Name,
                AttendedCountryClubs = pro.ProductInCategories.Where(cat => cat.ProductID == 1),
            });
            var model = new ProductListModel
            {
                Products = products.OrderBy(p => p.Name).Select(p => new ListItem
                {
                    ID            = p.ID,
                    Name          = p.Name,
                    categoryNames = p.ProductInCategories.Select(x => x.ProductCategory.Name).ToList(),
                }).ToList()
            };

            return(model);
        }