//method to view my products
        public async Task <IActionResult> MyProductsList()
        {
            var model = new MyProductsViewModel();

            var user = await GetCurrentUserAsync();

            var myProducts = await _context.Product
                             .Include(p => p.User)
                             .Where(p => p.UserId == user.Id).ToListAsync();

            model.Products = myProducts;
            return(View(model));
        }
        public ActionResult MyProducts()
        {
            var currentUserId = User.Identity.GetUserId();
            var user          = _context.Users.Single(u => u.Id == currentUserId);
            var products      = _context.Products.Where(m => m.UserId == currentUserId).Include(p => p.User).Include(c => c.ProductCategory).ToList();
            var pictures      = _context.PIctureInfos.Where(m => m.UserId == currentUserId).ToList();

            var myProducts = new MyProductsViewModel
            {
                Product = products,
                Picture = pictures,
                Users   = user
            };

            return(View(myProducts));
        }
Example #3
0
        public async Task <IActionResult> MyProducts()
        {
            var user = await userManager.FindByNameAsync(User.Identity.Name);

            var products = await _context.Products.ToListAsync();

            MyProductsViewModel model = new MyProductsViewModel();

            foreach (var product in products)
            {
                if (product.Seller == user.UserName)
                {
                    model.ProductList.Add(product);
                }
            }
            return(View(model));
        }