public ViewResult Index()
        {
            ViewBag.Title = "Basket";
            var items = _storeRep.getStoreitems();

            _storeRep.listStoreItems = items;

            var obj = new StoreProductViewModel
            {
                storeProduct = _storeRep
            };

            return(View(obj));
        }
Exemplo n.º 2
0
 public void OnGet(StoreProductViewModel storeModel, int storeId, int?pageId)
 {
     //SetStoreModelAsync(Id);
     PrdModel = _productService.GetStoreProducts(storeId, pageId ?? 0, Constants.ITEMS_PER_PAGE, storeModel.BrandFilterApplied, storeModel.CategoryFilterApplied, storeModel.SearchText);
 }
Exemplo n.º 3
0
        public StoreProductViewModel GetStoreProducts(int storeId, int pageIndex, int itemsPage, string brandName = "All", string categoryName = "All", string searchText = "")
        {
            _logger.LogInformation("GetStoreProducts called.");

            if (String.IsNullOrEmpty(brandName))
            {
                brandName = "All";
            }

            if (String.IsNullOrEmpty(categoryName))
            {
                categoryName = "All";
            }

            if (String.IsNullOrEmpty(searchText))
            {
                searchText = "";
            }

            // var filterSpecification = new ProductFilterSpecification(string.Empty);
            // var filterPaginatedSpecification =
            //      new ProductFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, string.Empty);


            //var itemsOnPage = _productRepository.FilterBy(p => p.StoreId == storeId);


            //var filterSpecification = new CatalogFilterSpecification(brandId, typeId);
            //var filterPaginatedSpecification =
            //    new CatalogFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, brandId, typeId);

            // the implementation below using ForEach and Count. We need a List.
            //var itemsOnPage = _productRepository.Find(filterPaginatedSpecification);
            var totalItems = _productRepository.Count(
                x => x.StoreId == storeId & (x.Brand == brandName || brandName == "All")
                &
                (x.Category == categoryName || categoryName == "All")
                &
                (x.Name.ToLower().Contains(searchText.ToLower()) || searchText == "")
                );

            //var test = _productRepository.Find(x => x.StoreId == storeId,1,2);

            //var test1 = _productRepository.Find(x => x.StoreId == storeId, 2, 2);

            //var command1 = new BsonDocument { { "StoreId", storeId } };
            //var command2 = new BsonDocument { { "Brand", brandName } };

            //var filterBuilder = Builders<BsonDocument>.Filter;
            //var filter = filterBuilder.Eq("StoreId", storeId)
            //& filterBuilder.Eq("Brand", brandName);


            var itemsOnPage = _productRepository.Find(
                x => x.StoreId == storeId & (x.Brand == brandName || brandName == "All")
                &
                (x.Category == categoryName || categoryName == "All")
                &
                (x.Name.ToLower().Contains(searchText.ToLower()) || searchText == "")
                , pageIndex, itemsPage);
            //var itemsOnPage = _productRepository.Find(filterBuilder, pageIndex, itemsPage);

            var brands = _brandRepository.FilterBy(x => x.StoreId == storeId);

            //var brandsList = brands.Select(i => new SelectListItem()
            //{
            //Text = i.Name,
            //Value = i.Name //i.SecondaryId.ToString()
            //});

            //brandsList.Add(new SelectListItem() { Text = "All", Value = "All" });

            //brandsList.OfType<object>().Concat(second);

            //var x = brandsList.ToList();

            var categories = _categoryRepository.FilterBy(x => x.StoreId == storeId);

            var vm = new StoreProductViewModel()
            {
                StoreId               = storeId,
                BrandFilterApplied    = brandName ?? "All",
                CategoryFilterApplied = categoryName ?? "All",
                SearchText            = searchText ?? "",
                StoreProducts         = itemsOnPage.Select(i => new StoreProductItemViewModel()
                {
                    Id          = i.Id.ToString(),
                    SecondaryId = i.SecondaryId,
                    StoreId     = i.StoreId,
                    ProductId   = i.ProductId,
                    Name        = i.Name,
                    PictureUri  = _uriComposer.ComposePicUri(i.PictureUri),
                    Description = i.Description,
                    Price       = i.Price,
                    Amount      = i.Amount,
                    IsMedical   = i.IsMedical,
                    OptionId    = i.OptionId,
                    PercentCbd  = i.PercentCbd,
                    PercentThc  = i.PercentThc,
                    Slung       = i.Slung,
                    StrainType  = i.StrainType,
                    Brand       = i.Brand,
                    Category    = i.Category,
                }),
                PaginationInfo = new PaginationInfoViewModel()
                {
                    StoreId      = storeId,
                    ActualPage   = pageIndex,
                    ItemsPerPage = itemsOnPage.Count(),
                    TotalItems   = totalItems,
                    TotalPages   = int.Parse(Math.Ceiling(((decimal)totalItems / itemsPage)).ToString())
                },
                Brands     = GetBrands(storeId),
                Categories = GetCategories(storeId)
            };

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

            return(vm);
        }