Ejemplo n.º 1
0
        // GET: Product
        public ActionResult Index(string seo_url)
        {
            var product_desc = db.oc_product_description.SingleOrDefault(r => r.seo_url == seo_url);
            var product_id   = product_desc.product_id;
            var product      = db.oc_product.Find(product_id);
            var product_alternative_images = db.oc_product_image.Where(r => r.product_id == product_id).OrderBy(r => r.sort_order);
            var model = new ProductIndexViewmodel()
            {
                product                    = product,
                product_description        = product_desc,
                product_alternative_images = product_alternative_images,
            };

            #region Tạo thanh breadscrumb
            // targeted->parent_of_targeted ..... ->top_category
            var root_category_id = db.oc_product_to_category
                                   .Where(r => r.product_id == product_desc.product_id)
                                   .FirstOrDefault()
                                   .category_id;
            var fist_category_id = root_category_id;
            var category_tree    = new List <oc_category_description>();
            while (true)
            {
                var next_category_id = db.oc_category.SingleOrDefault(r => r.category_id == root_category_id).parent_id;
                if (next_category_id != 0)
                {
                    if (!db.oc_category.Any(r => r.category_id == next_category_id))
                    {
                        break;
                    }

                    category_tree.Add(db.oc_category_description.SingleOrDefault(r => r.category_id == next_category_id));
                    root_category_id = next_category_id;
                }
                else
                {
                    break;
                }
            }

            // top_category -> child_of_top -> ... -> targeted
            category_tree.Reverse();
            if (db.oc_category_description.Any(r => r.category_id == fist_category_id))
            {
                category_tree.Add(db.oc_category_description.SingleOrDefault(r => r.category_id == fist_category_id));
            }
            model.breadscrumb = category_tree;
            #endregion
            return(View(model));
        }
        // GET: Products
        public async Task<IActionResult> Index(string Ptype)
        {
            var model = new ProductIndexViewmodel();

            // Build list of Product instances for display in view
            // LINQ is awesome
            model.GroupedProducts = await (
                from t in _context.ProductType
                join p in _context.Product
                    on t.ProductTypeId equals p.ProductTypeId
                group new { t, p } by new { t.ProductTypeId, t.Label } into grouped
                select new GroupedProducts
                {
                    TypeId = grouped.Key.ProductTypeId,
                    TypeName = grouped.Key.Label,
                    ProductCount = grouped.Select(x => x.p.ProductId).Count(),
                    Products = grouped.Select(x => x.p).Take(3).ToList()
                }).ToListAsync();

            return View(model);
        }
Ejemplo n.º 3
0
        // GET: /Product/
        public ActionResult Index()
        {
            var _myViewmodel = new List<ProductIndexViewmodel>();

            var _product = from p in db.Products
                           orderby p.ProductId descending
                           select p;

            //Adding all the records in Product object to the newly created List
            foreach (Product p in _product)
            {
                var productIndex = new ProductIndexViewmodel()
                {
                    ProductName = p.ProductName,
                    ProductDescripton = p.ProductDescripton,
                    ProductQuantity = p.ProductQuantity,
                    ProductTypeSelected = p.ProductTypeId.ToString(),
                    ProductSKU = p.ProductSKU,
                    ProductROL = p.ProductROL,
                    ProductRetailPrice = p.ProductRetailPrice,
                    SupplierName = p.supplier.SupplierName,
                    StoreName = p.store.StoreName,
                    ProductTypeName = p.producttype.ProductTypeName

                };
                _myViewmodel.Add(productIndex);
            }
            return View(_myViewmodel);
        }