private async Task AddToSubcategories(ICollection <string> subcategories, string productId)
        {
            if (subcategories != null && subcategories.Count > 0)
            {
                string[] subcategoryIds = subcategories.ToArray();

                for (int i = 0; i < subcategoryIds.Length; i++)
                {
                    SubcategoryProduct subcategoryProduct = new SubcategoryProduct
                    {
                        SubcategoryId = subcategoryIds[i],
                        ProductId     = productId
                    };

                    await this.db.SubcategoryProducts.AddAsync(subcategoryProduct);

                    await this.db.SaveChangesAsync();
                }
            }
        }
Esempio n. 2
0
        // GET: subcategory
        public async Task <ActionResult> details(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            var subcategory = await db.SubCategories.FindAsync(id);

            if (subcategory == null)
            {
                return(HttpNotFound());
            }
            SubcategoryProduct model = new SubcategoryProduct
            {
                SubCategory = subcategory,
                Products    = db.Products.Where(i => i.SubCategoryId == subcategory.Id).ToList()
            };

            //Send to route
            ViewBag.RouteController = RouteData.Values["controller"];
            ViewBag.RouteAction     = RouteData.Values["action"];
            return(View(model));
        }
 public void Insert(SubcategoryProduct subcategoryProduct)
 {
     entities.SubcategoryProducts.Add(subcategoryProduct);
 }