Example #1
0
        public IActionResult Index()
        {
            ProdCatWrapper newWrapper = new ProdCatWrapper();

            newWrapper.Products = dbContext.Products.ToList();
            return(View("Index", newWrapper));
        }
Example #2
0
        public IActionResult ViewCategories()
        {
            ProdCatWrapper categoryWrapper = new ProdCatWrapper();

            categoryWrapper.Categories = dbContext.Categories.ToList();
            return(View("ViewCategories", categoryWrapper));
        }
Example #3
0
 public IActionResult UpdateCateAssociation(int categoryId, ProdCatWrapper fromCateAssociationForm)
 {
     fromCateAssociationForm.Association.CategoryId = categoryId;
     dbContext.Add(fromCateAssociationForm.Association);
     dbContext.SaveChanges();
     return(RedirectToAction("DisplayOneCategory"));
 }
Example #4
0
 public IActionResult UpdateProdAssociation(int productId, ProdCatWrapper fromAssociationForm)
 {
     fromAssociationForm.Association.ProductId = productId;
     dbContext.Add(fromAssociationForm.Association);
     dbContext.SaveChanges();
     return(RedirectToAction("DisplayOneProduct"));
 }
Example #5
0
 public IActionResult createcategory(ProdCatWrapper fromCategoryForm)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(fromCategoryForm.Category);
         dbContext.SaveChanges();
         return(RedirectToAction("ViewCategories", fromCategoryForm));
     }
     else
     {
         return(View("ViewCategories", fromCategoryForm));
     }
 }
Example #6
0
        public IActionResult DisplayOneCategory(int categoryId)
        {
            ProdCatWrapper thisCategory = new ProdCatWrapper();
            Category       thisCat      = dbContext.Categories
                                          .Include(c => c.ProductAssociation)
                                          .ThenInclude(p => p.Product)
                                          .FirstOrDefault(c => c.CategoryId == categoryId);
            List <Product> ExcludeThis = new List <Product>();

            thisCat.ProductAssociation.ForEach(pa => ExcludeThis.Add(pa.Product));

            thisCategory.Category = dbContext.Categories
                                    .Include(p => p.ProductAssociation)
                                    .ThenInclude(p => p.Product)
                                    .FirstOrDefault(c => c.CategoryId == categoryId);
            // This is including the product association but it is excluding the "ExcludeThis" List<Product> above.
            thisCategory.Products = dbContext.Products.Except(ExcludeThis).ToList();
            return(View(thisCategory));
        }
Example #7
0
        public IActionResult DisplayOneProduct(int productId)
        {
            ProdCatWrapper thisProduct = new ProdCatWrapper();
            Product        thisProd    = dbContext.Products
                                         .Include(c => c.CategoryAssociation)
                                         .ThenInclude(p => p.Category)
                                         .FirstOrDefault(c => c.ProductId == productId);
            List <Category> ExcludeThis = new List <Category>();

            thisProd.CategoryAssociation.ForEach(pa => ExcludeThis.Add(pa.Category));

            thisProduct.Product = dbContext.Products
                                  .Include(p => p.CategoryAssociation)
                                  .ThenInclude(p => p.Category)
                                  .FirstOrDefault(c => c.ProductId == productId);
            // This is including the category association but it is excluding the "ExcludeThis" List<Category> above.
            thisProduct.Categories = dbContext.Categories.Except(ExcludeThis).ToList();
            return(View(thisProduct));
        }
Example #8
0
 public IActionResult CreateProduct(ProdCatWrapper fromForm)
 {
     dbContext.Add(fromForm.Product);
     dbContext.SaveChanges();
     return(RedirectToAction("Index", fromForm));
 }