Beispiel #1
0
 public RedirectToActionResult EditCategory(int CategoryId, CategoryWithProducts newPro)
 {
     newPro.Association.CategoryId = CategoryId;
     dbContext.Add(newPro.Association);
     dbContext.SaveChanges();
     return(RedirectToAction("CatWithProducts", new{ CategoryId = CategoryId }));
 }
Beispiel #2
0
        public CategoryWithProducts ListOfProductsForCatViewModel(int id)
        {
            CategoryWithProducts CWP = new CategoryWithProducts();

            CWP.CurrentCategory = dbContext.Categories
                                  .Include(c => c.ProductAssociation)
                                  .ThenInclude(cp => cp.Product)
                                  .FirstOrDefault(c => c.CategoryId == id);

            CWP.ListOfProducts = dbContext.Products
                                 .Include(p => p.CategoryAssociation)
                                 .ThenInclude(pc => pc.Category)
                                 .Where(p => !CWP.CurrentCategory.ProductAssociation.Select(pc => pc.Product).Contains(p))
                                 .ToList();
            return(CWP);
        }
Beispiel #3
0
        public async ValueTask <List <CategoryWithProducts> > GetCategoriesWithFiveAndMoreProducts()
        {
            try
            {
                var result = await connection.QueryAsync <Category, int, CategoryWithProducts>(
                    SpName.CategoriesWithFiveProducts, (c, count) =>
                {
                    CategoryWithProducts category = new CategoryWithProducts();
                    category.Category             = c;
                    category.CountOfProducts      = count;
                    return(category);
                },
                    param : null,
                    commandType : CommandType.StoredProcedure,
                    splitOn : "CountOfProducts");

                return(result.ToList());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
        public ViewResult CatWithProducts(int CategoryId)
        {
            CategoryWithProducts viewModel = ListOfProductsForCatViewModel(CategoryId);

            return(View("CatWithProducts", viewModel));
        }