示例#1
0
        public ActionResult VendorNavigation(int currentVendorId)
        {
            var customerRolesIds = _workContext.CurrentCustomer.CustomerRoles
            .Where(cr => cr.Active).Select(cr => cr.Id).ToList();
            string cacheKey = string.Format(ModelCacheEventConsumer.VENDOR_NAVIGATION_MODEL_KEY, currentVendorId, _workContext.WorkingLanguage.Id, string.Join(",", customerRolesIds));
            var cacheModel = _cacheManager.Get(cacheKey, () =>
            {
                var currentVendor = _vendorService.GetVendorById(currentVendorId);

                var vendors = _vendorService.GetAllVendors();
                var model = new VendorNavigationModel()
                {
                    TotalVendors = vendors.Count
                };

                foreach (var vendor in vendors.Take(_catalogSettings.ManufacturersBlockItemsToDisplay))
                {
                    var modelMan = new VendorBriefInfoModel()
                    {
                        Id = vendor.Id,
                        Name = vendor.GetLocalized(x => x.Name),
                        SeName = vendor.GetSeName(),
                        IsActive = currentVendor != null && currentVendor.Id == vendor.Id,
                    };
                    model.Vendors.Add(modelMan);
                }
                return model;
            });

            return PartialView(cacheModel);
        }
示例#2
0
        public ActionResult VendorNavigation()
        {
            if (_vendorSettings.VendorsBlockItemsToDisplay == 0)
                return Content("");

            string cacheKey = ModelCacheEventConsumer.VENDOR_NAVIGATION_MODEL_KEY;
            var cacheModel = _cacheManager.Get(cacheKey, () =>
            {
                var vendors = _vendorService.GetAllVendors(pageSize: _vendorSettings.VendorsBlockItemsToDisplay);
                var model = new VendorNavigationModel()
                {
                    TotalVendors = vendors.TotalCount
                };

                foreach (var vendor in vendors)
                {
                    model.Vendors.Add(new VendorBriefInfoModel()
                    {
                        Id = vendor.Id,
                        Name = vendor.GetLocalized(x => x.Name),
                        SeName = vendor.GetSeName(),
                    });
                }
                return model;
            });

            if (cacheModel.Vendors.Count == 0)
                return Content("");
            
            return PartialView(cacheModel);
        }