Esempio n. 1
0
        public virtual async Task <CategoryBrowsingViewModel> GetViewModelAsync()
        {
            if (_viewModel != null)
            {
                return(_viewModel);
            }
            var categoryId = CategoryMetaContext.GetCategoryId();

            _viewModel = await CategoryBrowsingViewService.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId           = categoryId,
                CategoryName         = await GetCategoryNameAsync(categoryId).ConfigureAwait(false),
                BaseUrl              = RequestUtils.GetBaseUrl(Request).ToString(),
                IsAllProducts        = CategoryMetaContext.GetIsAllProductPage(),
                NumberOfItemsPerPage = SearchConfiguration.MaxItemsPerPage,
                Page                 = CurrentPage,
                SortBy               = SortBy,
                SortDirection        = SortDirection,
                InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync().ConfigureAwait(false),
                SelectedFacets       = SearchUrlProvider.BuildSelectedFacets(Request.QueryString).ToList(),
                CultureInfo          = ComposerContext.CultureInfo,
            }).ConfigureAwait(false);

            return(_viewModel);
        }
Esempio n. 2
0
        public async Task <CategoryBrowsingViewModel> GetCategoryAvailableProductsAsync(GetBrowseCategoryParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            if (ViewModel != null)
            {
                return(ViewModel);
            }

            ViewModel = await CategoryBrowsingViewService.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId           = param.CategoryId,
                CategoryName         = await GetCategoryNameAsync(param.CategoryId),
                BaseUrl              = RequestUtils.GetBaseUrl(param.Request).ToString(),
                IsAllProducts        = CategoryMetaContext.GetIsAllProductPage(),
                Page                 = param.Page,
                SortBy               = param.SortBy,
                SortDirection        = param.SortDirection,
                InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync(),
                SelectedFacets       = SearchUrlProvider.BuildSelectedFacets(param.Request.QueryString).ToList(),
                CultureInfo          = ComposerContext.CultureInfo,
            }).ConfigureAwait(false);

            return(ViewModel);
        }
        protected ActionResult ExecuteBrowsing(string emptyView, string filledView, Func <CategoryBrowsingViewModel, object> viewModelSelector, object emptyViewModel, int page, string sortBy = null, string sortDirection = null)
        {
            var categoryId = CategoryMetaContext.GetCategoryId();

            if (string.IsNullOrWhiteSpace(categoryId))
            {
                return(View(emptyView, emptyViewModel));
            }

            var container = RequestContext.GetCategoryAvailableProductsAsync(new GetBrowseCategoryParam
            {
                Request       = Request,
                Page          = page,
                SortBy        = sortBy,
                SortDirection = sortDirection,
                CategoryId    = categoryId,
            }).Result;

            var viewName = container.ProductSearchResults.TotalCount <= 0 ? emptyView : filledView;
            var model    = viewModelSelector.Invoke(container);

            if (model is CategoryBrowsingViewModel)
            {
                ExtendSpecificViewsWithContext(filledView, (CategoryBrowsingViewModel)model);
            }

            return(View(viewName, model));
        }