Beispiel #1
0
 public IActionResult AddCategory(int productid, ShowAllWrapper thisCategory)
 {
     thisCategory.Association.ProductId = productid;
     if (ModelState.IsValid)
     {
         dbContext.Add(thisCategory.Association);
         dbContext.SaveChanges();
         return(RedirectToAction("ProductThis", new { productid = productid }));
     }
     else
     {
         return(RedirectToAction("ProductThis", new { productid = productid }));
     }
 }
Beispiel #2
0
 public IActionResult AddProduct(int categoryid, ShowAllWrapper thisProduct)
 {
     thisProduct.Association.CategoryId = categoryid;
     if (ModelState.IsValid)
     {
         dbContext.Add(thisProduct.Association);
         dbContext.SaveChanges();
         return(RedirectToAction("CategoryThis", new { categoryid = categoryid }));
     }
     else
     {
         return(RedirectToAction("CategoryThis", new { categoryid = categoryid }));
     }
 }
Beispiel #3
0
        public IActionResult ProductThis(int productid)
        {
            ShowAllWrapper vMod = new ShowAllWrapper();

            vMod.ThisProduct = dbContext.Products
                               .Include(b => b.CategoriesfromProduct)
                               .ThenInclude(v => v.Category)
                               .FirstOrDefault(b => b.ProductId == productid);
            List <Category> AllCategories = dbContext.Categories.ToList();
            List <Category> NewList       = new List <Category> {
            };

            foreach (var i in vMod.ThisProduct.CategoriesfromProduct)
            {
                NewList.Add(i.Category);
            }
            vMod.CatsNotInProd = AllCategories
                                 .Except(NewList).ToList();
            return(View(vMod));
        }
Beispiel #4
0
        public IActionResult CategoryThis(int categoryid)
        {
            ShowAllWrapper vMod = new ShowAllWrapper();

            vMod.ThisCategory = dbContext.Categories
                                .Include(b => b.ProductsfromCategory)
                                .ThenInclude(v => v.Product)
                                .FirstOrDefault(b => b.CategoryId == categoryid);
            List <Product> AllProducts = dbContext.Products.ToList();
            List <Product> NewList     = new List <Product> {
            };

            foreach (var i in vMod.ThisCategory.ProductsfromCategory)
            {
                NewList.Add(i.Product);
            }
            vMod.ProdsNotInCat = AllProducts
                                 .Except(NewList).ToList();
            return(View(vMod));
        }