public IActionResult Index() { ProdCatWrapper newWrapper = new ProdCatWrapper(); newWrapper.Products = dbContext.Products.ToList(); return(View("Index", newWrapper)); }
public IActionResult ViewCategories() { ProdCatWrapper categoryWrapper = new ProdCatWrapper(); categoryWrapper.Categories = dbContext.Categories.ToList(); return(View("ViewCategories", categoryWrapper)); }
public IActionResult UpdateCateAssociation(int categoryId, ProdCatWrapper fromCateAssociationForm) { fromCateAssociationForm.Association.CategoryId = categoryId; dbContext.Add(fromCateAssociationForm.Association); dbContext.SaveChanges(); return(RedirectToAction("DisplayOneCategory")); }
public IActionResult UpdateProdAssociation(int productId, ProdCatWrapper fromAssociationForm) { fromAssociationForm.Association.ProductId = productId; dbContext.Add(fromAssociationForm.Association); dbContext.SaveChanges(); return(RedirectToAction("DisplayOneProduct")); }
public IActionResult createcategory(ProdCatWrapper fromCategoryForm) { if (ModelState.IsValid) { dbContext.Add(fromCategoryForm.Category); dbContext.SaveChanges(); return(RedirectToAction("ViewCategories", fromCategoryForm)); } else { return(View("ViewCategories", fromCategoryForm)); } }
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)); }
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)); }
public IActionResult CreateProduct(ProdCatWrapper fromForm) { dbContext.Add(fromForm.Product); dbContext.SaveChanges(); return(RedirectToAction("Index", fromForm)); }