示例#1
0
        public async Task <ProductsIndexViewModel> GetProducts(int pageIndex, int pageSize)
        {
            logger.LogInformation("GetProducts called");

            var response = await productApi.ListProductsAsync(
                new ListProductsRequest
            {
                PageIndex = pageIndex,
                PageSize  = pageSize
            }
                );

            var vm = new ProductsIndexViewModel
            {
                Products       = mapper.Map <List <ProductViewModel> >(response.Products),
                PaginationInfo = new PaginationInfoViewModel()
                {
                    ActualPage   = pageIndex,
                    ItemsPerPage = response.Products.Count,
                    TotalItems   = response.TotalProducts,
                    TotalPages   = int.Parse(Math.Ceiling(((decimal)response.TotalProducts / pageSize)).ToString())
                }
            };

            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";

            return(vm);
        }
示例#2
0
        private ProductsIndexViewModel prepareProductSearchViewModel(int page           = 1, int pageSize      = DEFAULT_PAGE_SIZE,
                                                                     string keywords    = null, int?categoryId = null, bool?featured = null, bool?visible = null,
                                                                     string orderColumn = null, bool orderAsc  = true)
        {
            if (keywords == "null")
            {
                keywords = null;
            }
            var orderExpr = productFinder.CreateOrderExpr(orderColumn).Expand();
            var products  = productFinder.Find(categoryId, false, keywords, featured, visible,
                                               orderExpr: orderExpr, orderAsc: orderAsc);
            var model = new ProductsIndexViewModel
            {
                Page        = page,
                PageSize    = pageSize,
                TotalItems  = products.Count(),
                OrderColumn = orderColumn,
                OrderAsc    = orderAsc,
                Keywords    = keywords,
            };

            model.TotalPages = ((model.TotalItems - 1) / pageSize) + 1;
            if (model.TotalPages < model.Page)
            {
                model.Page = model.TotalPages;
            }
            model.Products = Mapper.Map <List <ProductSearchViewModel> >(products.GetPage(model.Page, model.PageSize));
            return(model);
        }
示例#3
0
        public ProductsIndexViewModel CategoryWhitProducts(string categoryId = null)
        {
            var model = new ProductsIndexViewModel()
            {
                Categories = this.categoriesRepository
                             .AllAsNoTracking()
                             .Select(x => new CategoryViewModel()
                {
                    Id   = x.Id,
                    Name = x.Name,
                }).ToList(),
            };

            if (this.categoriesRepository.All().Any(x => x.Id == categoryId))
            {
                model.Products = this.productsRepo
                                 .All()
                                 .Where(x => x.CategoryId == categoryId)
                                 .Select(x => new MenuProductViewModel()
                {
                    Id        = x.Id,
                    Name      = x.Name,
                    ImageUrl  = x.ImageUrl != null ? x.ImageUrl : GlobalConstants.DefaultProductImage,
                    IsOneSize = x.Sizes.Count == 1,
                    Sizes     = x.Sizes.Select(s => new ProductSizeViewModel()
                    {
                        SizeName = s.SizeName,
                        Price    = s.Price,
                    }).ToList(),
                    Weight = x.Sizes.Count == 1 ? x.Sizes.FirstOrDefault().Weight : default,
示例#4
0
        public ActionResult Index(string q)
        {
            var model = new ProductsIndexViewModel {
                Products = _session.Query <Product>()
            };

            return(View(model));
        }
        public IActionResult PreviousWork()
        {
            var productIndexViewModel = new ProductsIndexViewModel();

            productIndexViewModel.Products = _productRepository.GetAllProducts;

            return(View(productIndexViewModel));
        }
        public ActionResult Index()
        {
            var products  = this.Data.Products.All().Project().To <ProductIndexViewModel>().ToList();
            var viewModel = new ProductsIndexViewModel {
                Products = products
            };

            return(this.View(viewModel));
        }
        public IActionResult Index()
        {
            var productIndexViewModel = new ProductsIndexViewModel();

            productIndexViewModel.Products        = _productRepository.GetAllProducts;
            productIndexViewModel.CurrentCategory = "Best Sellers";

            return(View(productIndexViewModel));
        }
示例#8
0
        public async Task <ActionResult> Index()
        {
            var products = await _productServices.GetNavigationList();

            var data = new ProductsIndexViewModel
            {
                ProductsCollection = Mapper.Map <List <ProductViewModel> >(products)
            };

            return(View("Index", data));
        }
示例#9
0
        public IActionResult Index(AllProductsIndexInputViewModel input, int page = 1)
        {
            var model = new ProductsIndexViewModel()
            {
                Colors = this.productService.GetColors(),
                Sizes  = this.productService.GetSizes(),
                Brands = this.productService.GetBrands(),
            };

            var products = this.productService.GetProductsByFilterWithPagenation <HomeIndexProductViewModel>(input.ParentCategoryName, input.ChildCategoryName, input.Color, input.Size, input.BrandName, input.SearchString, ItemsPerPage, (page - 1) * ItemsPerPage);

            if (products == null)
            {
                return(this.NotFound());
            }

            model.Products = products;

            var sb = new StringBuilder();

            sb.AppendLine(!string.IsNullOrWhiteSpace(input.SearchString) ? $"Search result for : {input.SearchString}" : string.Empty);
            sb.AppendLine();
            sb.Append(input.ParentCategoryName != null ? $"Category : {input.ParentCategoryName}" : string.Empty);
            sb.Append(input.ChildCategoryName != null ? $" / {input.ChildCategoryName}" : string.Empty);
            sb.Append(input.Color != null ? $" / Color : {input.Color}" : string.Empty);
            sb.Append(input.Size != null ? $" / Size : {input.Size}" : string.Empty);
            sb.Append(input.BrandName != null ? $" / Brand : {input.BrandName}" : string.Empty);

            model.RouteInfo  = sb.ToString();
            model.InputModel = input;

            var count = this.productService.GetProductsByFilter(input.ParentCategoryName, input.ChildCategoryName, input.Color, input.Size, input.BrandName, input.SearchString).Count();

            model.PagesCount = (int)Math.Ceiling((double)count / ItemsPerPage);
            if (model.PagesCount == 0)
            {
                model.PagesCount = 1;
            }

            model.CurrentPage = page;

            return(this.View(model));
        }
示例#10
0
        public ProductsIndexViewModel GetProductItems()
        {
            _logger.LogInformation("GetProductItems called.");

            BasketApiClient client = new BasketApiClient(_config.APIBaseUrl);
            IEnumerable <ProductModelResponse> items = client.ProductService.GetProductsAsync().Result;

            //imrovment could be to add paging
            ProductsIndexViewModel result = new ProductsIndexViewModel()
            {
                ProductItems = items.Select(i => new ProductItemViewModel()
                {
                    Id    = i.ProductId,
                    Name  = i.Name,
                    Price = i.Price
                })
            };

            return(result);
        }
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();

            IList <Product> products = _productsRepository.GetAll();

            IList <Inventory> inventories = _inventoriesRepository.GetAll();

            int totalProduct = products
                               .Count();



            var viewModel = new ProductsIndexViewModel()
            {
                Products     = products,
                TotalProduct = totalProduct
            };

            return(View(viewModel));
        }
示例#12
0
        public IActionResult Index(string q)
        {
            var viewModel = new ProductsIndexViewModel();

            viewModel.Products = _dbContext.Products.Include(r => r.Category)
                                 .Where(r => q == null || r.Title.Contains(q) || r.Description.Contains(q))
                                 .Select(dbProd => new ProductViewModel
            {
                Id          = dbProd.Id,
                Title       = dbProd.Title,
                Description = dbProd.Description,
                Price       = dbProd.Price,
                Category    = dbProd.Category.Title
            }).ToList();
            viewModel.q          = q;
            viewModel.Categories = _dbContext.Categories.Select(dbCat => new CategoryViewModel
            {
                Id    = dbCat.Id,
                Title = dbCat.Title,
            }).ToList();
            return(View(viewModel));
        }
示例#13
0
        public ActionResult Index(string q)
        {
            var model = new ProductsIndexViewModel { Products = _session.Query<Product>() };

            return View(model);
        }
示例#14
0
 public async Task OnGet(int?pageId)
 {
     ProductsModel = await productsViewModelService.GetProducts(pageId ?? 0, Constants.ITEMS_PER_PAGE);
 }
示例#15
0
        public IActionResult Products()
        {
            ProductsIndexViewModel pv = new ProductsIndexViewModel();

            return(View(pv));
        }
示例#16
0
 private ProductsIndexViewModel prepareProductSearchViewModel(int page = 1, int pageSize = DEFAULT_PAGE_SIZE,
     string keywords = null, int? categoryId = null, bool? featured = null, bool? visible = null,
     string orderColumn = null, bool orderAsc = true)
 {
     if (keywords == "null") keywords = null;
     var orderExpr = productFinder.CreateOrderExpr(orderColumn).Expand();
     var products = productFinder.Find(categoryId, false, keywords, featured, visible,
         orderExpr: orderExpr, orderAsc: orderAsc);
     var model = new ProductsIndexViewModel
                 {
                     Page = page,
                     PageSize = pageSize,
                     TotalItems = products.Count(),
                     OrderColumn = orderColumn,
                     OrderAsc = orderAsc,
                     Keywords = keywords,
                 };
     model.TotalPages = ((model.TotalItems - 1)/pageSize) + 1;
     if (model.TotalPages < model.Page)
         model.Page = model.TotalPages;
     model.Products = Mapper.Map<List<ProductSearchViewModel>>(products.GetPage(model.Page, model.PageSize));
     return model;
 }