Пример #1
0
        public async Task <IViewComponentResult> InvokeAsync(int productId)
        {
            var quantityRemaining = await GetItemsAsync(productId);

            ProductCountViewModel model = new ProductCountViewModel
            {
                ProductCount = quantityRemaining
            };


            return(View(model));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var viewModel = new ProductCountViewModel();

            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user == null)
            {
                return(View(viewModel));
            }

            var productCount = _context.Product.Where(p => p.UserId == user.Id).Count();

            viewModel.ProductCount = productCount;

            return(View(viewModel));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var viewModel = new ProductCountViewModel();

            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user == null)
            {
                //because default integer is zero, just return the viewModel without adding to product count if not logged in
                return(View(viewModel));
            }

            var productCount = _context.Product.Where(prod => prod.UserId == user.Id).Count();

            viewModel.ProductCount = productCount;

            return(View(viewModel));
        }