/// <summary>
        /// Get category breadcrumb 
        /// </summary>
        /// <param name="category">Category</param>
        /// <param name="categoryService">Category service</param>
        /// <param name="aclService">ACL service</param>
        /// <param name="storeMappingService">Store mapping service</param>
        /// <param name="showHidden">A value indicating whether to load hidden records</param>
        /// <returns>Category breadcrumb </returns>
        public static IList<Category> GetCategoryBreadCrumb(this Category category,
            ICategoryService categoryService,
            IAclService aclService,
            IStoreMappingService storeMappingService,
            bool showHidden = false)
        {
            if (category == null)
                throw new ArgumentNullException("category");

            var result = new List<Category>();

            //used to prevent circular references
            var alreadyProcessedCategoryIds = new List<int>();

            while (category != null && //not null
                !category.Deleted && //not deleted
                (showHidden || category.Published) && //published
                (showHidden || aclService.Authorize(category)) && //ACL
                (showHidden || storeMappingService.Authorize(category)) && //Store mapping
                !alreadyProcessedCategoryIds.Contains(category.Id)) //prevent circular references
            {
                result.Add(category);

                alreadyProcessedCategoryIds.Add(category.Id);

                category = categoryService.GetCategoryById(category.ParentCategoryId);
            }
            result.Reverse();
            return result;
        }
Exemple #2
0
        /// <summary>
        /// Gets by type
        /// </summary>
        /// <returns>Picture Sliders</returns>
        public virtual async Task <IList <PictureSlider> > GetPictureSliders(SliderType sliderType, string objectEntry = "")
        {
            string cacheKey = string.Format(SLIDERS_MODEL_KEY, _storeContext.CurrentStore.Id, sliderType.ToString(), objectEntry);

            return(await _cacheBase.GetAsync(cacheKey, async() =>
            {
                var query = from s in _reporistoryPictureSlider.Table
                            where s.SliderTypeId == (int)sliderType && s.Published
                            select s;

                if (!string.IsNullOrEmpty(objectEntry))
                {
                    query = query.Where(x => x.ObjectEntry == objectEntry);
                }

                var items = await query.ToListAsync();
                return items.Where(c => _storeMappingService.Authorize(c)).ToList();
            }));
        }
Exemple #3
0
        /// <summary>
        /// Gets all checkout attributes
        /// </summary>
        /// <param name="storeId">Store identifier</param>
        /// <param name="excludeShippableAttributes">A value indicating whether we should exlude shippable attributes</param>
        /// <returns>Checkout attributes</returns>
        public virtual IList <CheckoutAttribute> GetAllCheckoutAttributes(int storeId = 0, bool excludeShippableAttributes = false)
        {
            var query = from ca in _checkoutAttributeRepository.Table
                        orderby ca.DisplayOrder, ca.Id
            select ca;
            var checkoutAttributes = query.ToList();

            if (storeId > 0)
            {
                //store mapping
                checkoutAttributes = checkoutAttributes.Where(ca => _storeMappingService.Authorize(ca)).ToList();
            }
            if (excludeShippableAttributes)
            {
                //remove attributes which require shippable products
                checkoutAttributes = checkoutAttributes.RemoveShippableAttributes().ToList();
            }
            return(checkoutAttributes);
        }
Exemple #4
0
        /// <summary>
        /// Gets all currencies
        /// </summary>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <param name="storeId">Load records allowed only in a specified store; pass 0 to load all records</param>
        /// <param name="loadCacheableCopy">A value indicating whether to load a copy that could be cached (workaround until Entity Framework supports 2-level caching)</param>
        /// <returns>Currencies</returns>
        public virtual IList <Currency> GetAllCurrencies(bool showHidden = false, int storeId = 0, bool loadCacheableCopy = true)
        {
            Func <IList <Currency> > loadCurrenciesFunc = () =>
            {
                var query = _currencyRepository.Table;
                if (!showHidden)
                {
                    query = query.Where(c => c.Published);
                }
                query = query.OrderBy(c => c.DisplayOrder).ThenBy(c => c.Id);
                return(query.ToList());
            };

            IList <Currency> currencies;

            if (loadCacheableCopy)
            {
                //cacheable copy
                var key = string.Format(NopDirectoryDefaults.CurrenciesAllCacheKey, showHidden);
                currencies = _cacheManager.Get(key, () =>
                {
                    var result = new List <Currency>();
                    foreach (var currency in loadCurrenciesFunc())
                    {
                        result.Add(new CurrencyForCaching(currency));
                    }
                    return(result);
                });
            }
            else
            {
                currencies = loadCurrenciesFunc();
            }

            //store mapping
            if (storeId > 0)
            {
                currencies = currencies
                             .Where(c => _storeMappingService.Authorize(c, storeId))
                             .ToList();
            }
            return(currencies);
        }
        /// <summary>
        /// Gets a topic
        /// </summary>
        /// <param name="systemName">The topic system name</param>
        /// <param name="storeId">Store identifier; pass 0 to ignore filtering by store and load the first one</param>
        /// <returns>Topic</returns>
        public virtual Topic GetTopicBySystemName(string systemName, string storeId = "")
        {
            if (String.IsNullOrEmpty(systemName))
            {
                return(null);
            }

            var query = _topicRepository.Table;

            query = query.Where(t => t.SystemName.ToLower() == systemName.ToLower());
            query = query.OrderBy(t => t.Id);
            var topics = query.ToList();

            if (!String.IsNullOrEmpty(storeId))
            {
                topics = topics.Where(x => _storeMappingService.Authorize(x, storeId)).ToList();
            }
            return(topics.FirstOrDefault());
        }
Exemple #6
0
        /// <summary>
        /// Gets all languages
        /// </summary>
        /// <param name="storeId">Load records allowed only in a specified store; pass 0 to load all records</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <param name="loadCacheableCopy">A value indicating whether to load a copy that could be cached (workaround until Entity Framework supports 2-level caching)</param>
        /// <returns>Languages</returns>
        public virtual IList <Language> GetAllLanguages(bool showHidden = false, int storeId = 0, bool loadCacheableCopy = true)
        {
            Func <IList <Language> > loadLanguagesFunc = () =>
            {
                var query = _languageRepository.Table;
                if (!showHidden)
                {
                    query = query.Where(l => l.Published);
                }
                query = query.OrderBy(l => l.DisplayOrder).ThenBy(l => l.Id);
                return(query.ToList());
            };

            IList <Language> languages;

            if (loadCacheableCopy)
            {
                //cacheable copy
                var key = string.Format(NopLocalizationDefaults.LanguagesAllCacheKey, showHidden);
                languages = _cacheManager.Get(key, () =>
                {
                    var result = new List <Language>();
                    foreach (var language in loadLanguagesFunc())
                    {
                        result.Add(new LanguageForCaching(language));
                    }
                    return(result);
                });
            }
            else
            {
                languages = loadLanguagesFunc();
            }

            //store mapping
            if (storeId > 0)
            {
                languages = languages
                            .Where(l => _storeMappingService.Authorize(l, storeId))
                            .ToList();
            }
            return(languages);
        }
        public ActionResult NewsItem(int newsItemId)
        {
            if (!_newsSettings.Enabled)
                return RedirectToRoute("HomePage");

            var newsItem = _newsService.GetNewsById(newsItemId);
            if (newsItem == null || 
                !newsItem.Published ||
                (newsItem.StartDateUtc.HasValue && newsItem.StartDateUtc.Value >= DateTime.UtcNow) ||
                (newsItem.EndDateUtc.HasValue && newsItem.EndDateUtc.Value <= DateTime.UtcNow) ||
                //Store mapping
                !_storeMappingService.Authorize(newsItem))
                return RedirectToRoute("HomePage");

            var model = new NewsItemModel();
            PrepareNewsItemModel(model, newsItem, true);

            return View(model);
        }
Exemple #8
0
        public virtual Topic GetTopicBySystemName(string systemName, int storeId = 0)
        {
            if (systemName.IsEmpty())
            {
                return(null);
            }

            var topic = _topicRepository.Table
                        .Where(x => x.SystemName == systemName)
                        .OrderBy(x => x.Id)
                        .FirstOrDefaultCached("db.topic.bysysname-" + systemName);

            if (storeId > 0 && topic != null && !_storeMappingService.Authorize(topic))
            {
                topic = null;
            }

            return(topic);
        }
        public virtual IActionResult Vote(int pollAnswerId)
        {
            var pollAnswer = _pollService.GetPollAnswerById(pollAnswerId);

            if (pollAnswer == null)
            {
                return(Json(new { error = "No poll answer found with the specified id" }));
            }

            var poll = _pollService.GetPollById(pollAnswer.PollId);

            if (!poll.Published || !_storeMappingService.Authorize(poll))
            {
                return(Json(new { error = "Poll is not available" }));
            }

            if (_customerService.IsGuest(_workContext.CurrentCustomer) && !poll.AllowGuestsToVote)
            {
                return(Json(new { error = _localizationService.GetResource("Polls.OnlyRegisteredUsersVote") }));
            }

            var alreadyVoted = _pollService.AlreadyVoted(poll.Id, _workContext.CurrentCustomer.Id);

            if (!alreadyVoted)
            {
                //vote
                _pollService.InsertPollVotingRecord(new PollVotingRecord
                {
                    PollAnswerId = pollAnswer.Id,
                    CustomerId   = _workContext.CurrentCustomer.Id,
                    CreatedOnUtc = DateTime.UtcNow
                });

                //update totals
                pollAnswer.NumberOfVotes = _pollService.GetPollVotingRecordsByPollAnswer(pollAnswer.Id).Count;
                _pollService.UpdatePoll(poll);
            }

            return(Json(new
            {
                html = RenderPartialViewToString("_Poll", _pollModelFactory.PreparePollModel(poll, true)),
            }));
        }
Exemple #10
0
        public virtual IActionResult NewsItem(int newsItemId)
        {
            if (!_newsSettings.Enabled)
            {
                return(RedirectToRoute("Homepage"));
            }

            var newsItem = _newsService.GetNewsById(newsItemId);

            if (newsItem == null)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //published?
                !newsItem.Published ||
                //availability dates
                !_newsService.IsNewsAvailable(newsItem) ||
                //Store mapping
                !_storeMappingService.Authorize(newsItem);
            //Check whether the current user has a "Manage news" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            var hasAdminAccess = _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageNews);

            if (notAvailable && !hasAdminAccess)
            {
                return(InvokeHttp404());
            }

            var model = new NewsItemModel();

            model = _newsModelFactory.PrepareNewsItemModel(model, newsItem, true);

            //display "edit" (manage) link
            if (hasAdminAccess)
            {
                DisplayEditLink(Url.Action("NewsItemEdit", "News", new { id = newsItem.Id, area = AreaNames.Admin }));
            }

            return(View(model));
        }
Exemple #11
0
        public virtual IActionResult Category(int categoryId, CatalogPagingFilteringModel command)
        {
            var category = _categoryService.GetCategoryById(categoryId);

            if (category == null || category.Deleted)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //published?
                !category.Published ||
                //ACL (access control list)
                !_aclService.Authorize(category) ||
                //Store mapping
                !_storeMappingService.Authorize(category);

            //Check whether the current user has a "Manage categories" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            if (notAvailable && !_permissionService.Authorize(StandardPermissionProvider.ManageCategories))
            {
                return(InvokeHttp404());
            }

            //display "edit" (manage) link
            if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageCategories))
            {
                DisplayEditLink(Url.Action("Edit", "Category", new { id = category.Id, area = AreaNames.Admin }));
            }

            //activity log
            _customerActivityService.InsertActivity("PublicStore.ViewCategory",
                                                    string.Format(_localizationService.GetResource("ActivityLog.PublicStore.ViewCategory"), category.Name), category);

            //model
            var model = _catalogModelFactory.PrepareCategoryModel(category, command);

            //template
            var templateViewPath = _catalogModelFactory.PrepareCategoryTemplateViewPath(category.CategoryTemplateId);

            return(View(templateViewPath, model));
        }
Exemple #12
0
        /// <summary>
        /// Prepare billing address model
        /// </summary>
        /// <param name="cart">Cart</param>
        /// <param name="selectedCountryId">Selected country identifier</param>
        /// <param name="prePopulateNewAddressWithCustomerFields">Pre populate new address with customer fields</param>
        /// <param name="overrideAttributesXml">Override attributes xml</param>
        /// <returns>Billing address model</returns>
        public virtual CheckoutBillingAddressModel PrepareBillingAddressModel(IList <ShoppingCartItem> cart,
                                                                              int?selectedCountryId = null,
                                                                              bool prePopulateNewAddressWithCustomerFields = false,
                                                                              string overrideAttributesXml = "")
        {
            var model = new CheckoutBillingAddressModel();

            model.ShipToSameAddress = true;

            //existing addresses
            var addresses = _workContext.CurrentCustomer.Addresses
                            .Where(a => a.Country == null ||
                                   (//published
                                       a.Country.Published &&
                                       //allow billing
                                       a.Country.AllowsBilling &&
                                       //enabled for the current store
                                       _storeMappingService.Authorize(a.Country)))
                            .ToList();

            foreach (var address in addresses)
            {
                var addressModel = new AddressModel();
                _addressModelFactory.PrepareAddressModel(addressModel,
                                                         address: address,
                                                         excludeProperties: false,
                                                         addressSettings: _addressSettings);
                model.ExistingAddresses.Add(addressModel);
            }

            //new address
            model.NewAddress.CountryId = selectedCountryId;
            _addressModelFactory.PrepareAddressModel(model.NewAddress,
                                                     address: null,
                                                     excludeProperties: false,
                                                     addressSettings: _addressSettings,
                                                     loadCountries: () => _countryService.GetAllCountriesForBilling(_workContext.WorkingLanguage.Id),
                                                     prePopulateWithCustomerFields: prePopulateNewAddressWithCustomerFields,
                                                     customer: _workContext.CurrentCustomer,
                                                     overrideAttributesXml: overrideAttributesXml);
            return(model);
        }
Exemple #13
0
        public ActionResult TopicDetails(int topicId, bool popup = false)
        {
            _helper.GetBreadcrumb(_breadcrumb, ControllerContext);

            var cacheKey   = string.Format(ModelCacheEventConsumer.TOPIC_BY_ID_KEY, topicId, _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id, _workContext.CurrentCustomer.GetRolesIdent());
            var cacheModel = _cacheManager.Get(cacheKey, () =>
            {
                var topic = _topicService.GetTopicById(topicId);
                if (topic == null || !topic.IsPublished)
                {
                    return(null);
                }

                if (!_storeMappingService.Authorize(topic))
                {
                    return(null);
                }

                if (!_aclService.Authorize(topic))
                {
                    return(null);
                }

                return(PrepareTopicModel(topic));
            });

            if (cacheModel == null || (!popup && cacheModel.RenderAsWidget))
            {
                return(HttpNotFound());
            }

            ViewBag.IsPopup = popup;

            if (!cacheModel.RenderAsWidget)
            {
                Services.DisplayControl.Announce(new Topic {
                    Id = cacheModel.Id
                });
            }

            return(View("TopicDetails", cacheModel));
        }
        /// <summary>
        /// Gets a product category mapping collection
        /// </summary>
        /// <param name="productId">Product identifier</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Product category mapping collection</returns>
        public virtual IList <ProductCategory> GetProductCategoriesByProductId(int productId, bool showHidden = false)
        {
            if (productId == 0)
            {
                return(new List <ProductCategory>());
            }

            string key = string.Format(PRODUCTCATEGORIES_ALLBYPRODUCTID_KEY, showHidden, productId, _workContext.CurrentCustomer.Id, _storeContext.CurrentStore.Id);

            return(_cacheManager.Get(key, () =>
            {
                var table = _productCategoryRepository.Table;
                var query = from pc in _productCategoryRepository.Expand(table, x => x.Category)
                            join c in _categoryRepository.Table on pc.CategoryId equals c.Id
                            where pc.ProductId == productId &&
                            !c.Deleted &&
                            (showHidden || c.Published)
                            orderby pc.DisplayOrder
                            select pc;

                var allProductCategories = query.ToList();
                var result = new List <ProductCategory>();
                if (!showHidden)
                {
                    foreach (var pc in allProductCategories)
                    {
                        // ACL (access control list) and store mapping
                        var category = pc.Category;
                        if (_aclService.Authorize(category) && _storeMappingService.Authorize(category))
                        {
                            result.Add(pc);
                        }
                    }
                }
                else
                {
                    // No filtering
                    result.AddRange(allProductCategories);
                }
                return result;
            }));
        }
Exemple #15
0
        public IList <Currency> GetAllCurrencies(bool showHidden = false, int storeId = 0)
        {
            string key        = string.Format(CURRENCIES_ALL_KEY, showHidden);
            var    currencies = _cacheManager.Get(key, () =>
            {
                var query = _currencyRepository.Table;
                if (!showHidden)
                {
                    query = query.Where(m => m.Published);
                }
                query = query.OrderBy(m => m.DisplayOrder);
                return(query.ToList());
            });

            if (storeId > 0)
            {
                currencies = currencies.Where(m => _storeMappingService.Authorize(m, storeId)).ToList();
            }
            return(currencies);
        }
Exemple #16
0
        /// <summary>
        /// Gets all currencies
        /// </summary>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <param name="storeId">Load records allowed only in a specified store; pass 0 to load all records</param>
        /// <returns>Currencies</returns>
        public virtual IList <Currency> GetAllCurrencies(bool showHidden = false, int storeId = 0)
        {
            var query = _currencyRepository.Table;

            if (!showHidden)
            {
                query = query.Where(c => c.Published);
            }
            query = query.OrderBy(c => c.DisplayOrder).ThenBy(c => c.Id);
            var currencies = query.ToList();

            //store mapping
            if (storeId > 0)
            {
                currencies = currencies
                             .Where(c => _storeMappingService.Authorize(c, storeId))
                             .ToList();
            }
            return(currencies);
        }
Exemple #17
0
        /// <summary>
        /// Gets all languages
        /// </summary>
        /// <param name="storeId">Load records allowed only in a specified store; pass 0 to load all records</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Languages</returns>
        public virtual IList <Language> GetAllLanguages(bool showHidden = false, int storeId = 0)
        {
            var query = _languageRepository.Table;

            if (!showHidden)
            {
                query = query.Where(l => l.Published);
            }
            query = query.OrderBy(l => l.DisplayOrder).ThenBy(l => l.Id);
            var languages = query.ToList();

            //store mapping
            if (storeId > 0)
            {
                languages = languages
                            .Where(l => _storeMappingService.Authorize(l, storeId))
                            .ToList();
            }
            return(languages);
        }
        public IViewComponentResult Invoke(int?productThumbPictureSize)
        {
            var products = _productService.GetAllProductsDisplayedOnHomepage();

            //ACL and store mapping
            products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList();
            //availability dates
            products = products.Where(p => _productService.ProductIsAvailable(p)).ToList();

            products = products.Where(p => p.VisibleIndividually).ToList();

            if (!products.Any())
            {
                return(Content(""));
            }

            var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList();

            return(View(model));
        }
        public IList <ProductCategory> GetProductCategoriesByVendorId(int vendorId, int storeId, bool showHidden = false)
        {
            if (vendorId == 0)
            {
                return(new List <ProductCategory>());
            }

            string key = string.Format(PRODUCTCATEGORIES_ALLBYVENDORID_KEY, showHidden, vendorId, _workContext.CurrentCustomer.Id, storeId);

            return(_cacheManager.Get(key, () =>
            {
                var query = from pc in _productCategoryRepository.Table
                            join p in _productRepository.Table on pc.ProductId equals p.Id
                            where p.VendorId == vendorId &&
                            !p.Deleted &&
                            (showHidden || p.Published)
                            orderby pc.DisplayOrder
                            select pc;

                var allProductCategories = query.ToList();
                var result = new List <ProductCategory>();
                if (!showHidden)
                {
                    foreach (var pc in allProductCategories)
                    {
                        //ACL (access control list) and store mapping
                        var category = pc.Category;
                        if (_aclService.Authorize(category) && _storeMappingService.Authorize(category, storeId))
                        {
                            result.Add(pc);
                        }
                    }
                }
                else
                {
                    //no filtering
                    result.AddRange(allProductCategories);
                }
                return result;
            }));
        }
Exemple #20
0
        public IList <CheckoutAttribute> GetAllCheckoutAttributes(int storeId = 0, bool excludeShippableAttributes = false)
        {
            string key = string.Format(CHECKOUTATTRIBUTES_ALL_KEY, storeId, excludeShippableAttributes);

            return(_cacheManager.Get(key, () =>
            {
                var query = from ca in _checkoutAttributeRepository.Table
                            orderby ca.DisplayOrder
                            select ca;
                var checkoutAttributes = query.ToList();
                if (storeId > 0)
                {
                    checkoutAttributes = checkoutAttributes.Where(m => _storeMappingService.Authorize(m)).ToList();
                }
                if (excludeShippableAttributes)
                {
                    checkoutAttributes = checkoutAttributes.RemoveShippableAttributes().ToList();
                }
                return checkoutAttributes;
            }));
        }
        public virtual CustomerAddressListModel PrepareCustomerAddressListModel()
        {
            var addresses = _workContext.CurrentCustomer.Addresses
                            //enabled for the current store
                            .Where(a => a.Country == null || _storeMappingService.Authorize(a.Country))
                            .ToList();

            var model = new CustomerAddressListModel();

            foreach (var address in addresses)
            {
                var addressModel = new AddressModel();
                _addressModelFactory.PrepareAddressModel(addressModel,
                                                         address: address,
                                                         excludeProperties: false,
                                                         addressSettings: _addressSettings,
                                                         loadCountries: () => _countryService.GetAllCountries(_workContext.WorkingLanguage.Id));
                model.Addresses.Add(addressModel);
            }
            return(model);
        }
        public virtual CustomerAddressListModel PrepareAddressList(Customer customer)
        {
            var model     = new CustomerAddressListModel();
            var addresses = customer.Addresses
                            .Where(a => a.CountryId == "" ||
                                   _storeMappingService.Authorize(_countryService.GetCountryById(a.CountryId))
                                   )
                            .ToList();

            foreach (var address in addresses)
            {
                var addressModel = new AddressModel();
                _addressViewModelService.PrepareModel(model: addressModel,
                                                      address: address,
                                                      excludeProperties: false,
                                                      loadCountries: () => _countryService.GetAllCountries(_workContext.WorkingLanguage.Id));
                model.Addresses.Add(addressModel);
            }

            return(model);
        }
Exemple #23
0
        public virtual IActionResult BlogPost(int blogPostId)
        {
            if (!_blogSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var blogPost = _blogService.GetBlogPostById(blogPostId);

            if (blogPost == null)
            {
                return(RedirectToRoute("HomePage"));
            }

            var hasAdminAccess = _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageBlog);

            //access to Blog preview
            if (!blogPost.IsAvailable() && !hasAdminAccess)
            {
                return(RedirectToRoute("HomePage"));
            }

            //Store mapping
            if (!_storeMappingService.Authorize(blogPost))
            {
                return(InvokeHttp404());
            }

            //display "edit" (manage) link
            if (hasAdminAccess)
            {
                DisplayEditLink(Url.Action("Edit", "Blog", new { id = blogPost.Id, area = AreaNames.Admin }));
            }

            var model = new BlogPostModel();

            _blogModelFactory.PrepareBlogPostModel(model, blogPost, true);

            return(View(model));
        }
Exemple #24
0
        public IViewComponentResult Invoke(string widgetZone, object additionalData)
        {
            var widget = _widgetZoneService.GetWidgetZoneBySystemName(widgetZone);

            //return empty result if widget zone has no slider
            if (widget == null)
            {
                return(Content(string.Empty));
            }

            //return empty result if widget zone isn't published
            if (!widget.Published)
            {
                return(Content(string.Empty));
            }

            //return empty page if widget zone aren't authorized
            if (!_aclService.Authorize(widget))
            {
                return(Content(string.Empty));
            }

            //return nothing if widget zone aren't authorized in current store
            if (!_storeMappingService.Authorize(widget))
            {
                return(Content(string.Empty));
            }

            //return empty result, if widget zone has no published slides
            var slides = _widgetZoneService.GetWidgetZoneSlides(widget.Id);

            if (!slides.Any())
            {
                return(Content(string.Empty));
            }

            var model = _publicModelFactory.PrepareWidgetZoneModel(widget);

            return(View("~/Plugins/Widgets.qBoSlider/Views/Public/PublicInfo.cshtml", model));
        }
        public async Task <CustomerAddressListModel> Handle(GetAddressList request, CancellationToken cancellationToken)
        {
            var model     = new CustomerAddressListModel();
            var addresses = new List <Address>();

            foreach (var item in request.Customer.Addresses)
            {
                if (string.IsNullOrEmpty(item.CountryId))
                {
                    addresses.Add(item);
                    continue;
                }
                var country = await _countryService.GetCountryById(item.CountryId);

                if (country != null || _storeMappingService.Authorize(country))
                {
                    addresses.Add(item);
                    continue;
                }
            }

            foreach (var address in addresses)
            {
                var countries = await _countryService.GetAllCountries(request.Language.Id);

                var addressModel = await _mediator.Send(new GetAddressModel()
                {
                    Language          = request.Language,
                    Store             = request.Store,
                    Model             = null,
                    Address           = address,
                    ExcludeProperties = false,
                    LoadCountries     = () => countries
                });

                model.Addresses.Add(addressModel);
            }

            return(model);
        }
        public virtual IActionResult BlogPost(int blogPostId)
        {
            if (!_blogSettings.Enabled)
            {
                return(RedirectToRoute("Homepage"));
            }

            var blogPost = _blogService.GetBlogPostById(blogPostId);

            if (blogPost == null)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //availability dates
                !_blogService.BlogPostIsAvailable(blogPost) ||
                //Store mapping
                !_storeMappingService.Authorize(blogPost);
            //Check whether the current user has a "Manage blog" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            var hasAdminAccess = _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageBlog);

            if (notAvailable && !hasAdminAccess)
            {
                return(InvokeHttp404());
            }

            //display "edit" (manage) link
            if (hasAdminAccess)
            {
                DisplayEditLink(Url.Action("BlogPostEdit", "Blog", new { id = blogPost.Id, area = AreaNames.Admin }));
            }

            var model = new BlogPostModel();

            _blogModelFactory.PrepareBlogPostModel(model, blogPost, true);

            return(View(model));
        }
Exemple #27
0
        /// <summary>
        /// Gets all currencies
        /// </summary>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <param name="storeId">Load records allowed only in a specified store; pass "" to load all records</param>
        /// <returns>Currencies</returns>
        public virtual async Task <IList <Currency> > GetAllCurrencies(bool showHidden = false, string storeId = "")
        {
            string key        = string.Format(CURRENCIES_ALL_KEY, showHidden);
            var    currencies = await _cacheManager.GetAsync(key, () =>
            {
                var query = _currencyRepository.Table;

                if (!showHidden)
                {
                    query = query.Where(c => c.Published);
                }
                query = query.OrderBy(c => c.DisplayOrder);
                return(query.ToListAsync());
            });

            //store mapping
            if (!String.IsNullOrEmpty(storeId))
            {
                currencies = currencies.Where(c => _storeMappingService.Authorize(c, storeId)).ToList();
            }
            return(currencies);
        }
Exemple #28
0
        public IList <Language> GetAllLanguages(bool showHidden = false, int storeId = 0)
        {
            string key       = string.Format(LANGUAGES_ALL_KEY, showHidden);
            var    languages = _cacheManager.Get(key, () =>
            {
                var query = _languageRepository.Table;
                if (!showHidden)
                {
                    query = query.Where(m => m.Published);
                }

                query = query.OrderBy(m => m.DisplayOrder);
                return(query.ToList());
            });

            if (storeId > 0)
            {
                languages = languages.Where(m => _storeMappingService.Authorize(m, storeId)).ToList();
            }

            return(languages);
        }
        public IViewComponentResult Invoke(int? productThumbPictureSize)
        {
            if (!_catalogSettings.RecommendedProductsEnabled)
                return Content("");

            var products = _productService.GetRecommendedProducts(_workContext.CurrentCustomer.GetCustomerRoleIds());

            //ACL and store mapping
            products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList();

            //availability dates
            products = products.Where(p => p.IsAvailable()).ToList();

            if (!products.Any())
                return Content("");

            //prepare model
            var model = _productWebService.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList();

            return View(model);

        }
Exemple #30
0
        /// <summary>
        /// Gets a topic
        /// </summary>
        /// <param name="systemName">The topic system name</param>
        /// <param name="storeId">Store identifier; pass 0 to ignore filtering by store and load the first one</param>
        /// <returns>Topic</returns>
        public virtual async Task <Topic> GetTopicBySystemName(string systemName, string storeId = "")
        {
            if (string.IsNullOrEmpty(systemName))
            {
                return(null);
            }

            string key = string.Format(TOPICS_BY_SYSTEMNAME, systemName, storeId);

            return(await _cacheManager.GetAsync(key, async() =>
            {
                var query = _topicRepository.Table;
                query = query.Where(t => t.SystemName.ToLower() == systemName.ToLower());
                query = query.OrderBy(t => t.Id);
                var topics = await query.ToListAsync();
                if (!String.IsNullOrEmpty(storeId))
                {
                    topics = topics.Where(x => _storeMappingService.Authorize(x, storeId)).ToList();
                }
                return topics.FirstOrDefault();
            }));
        }
Exemple #31
0
        protected async Task <bool> CheckPermission(Course course, Customer customer)
        {
            //Check whether the current user is a guest
            if (customer.IsGuest() && !_courseSettings.AllowGuestsToAccessCourse)
            {
                return(false);
            }

            //Check whether the current user has a "Manage course" permission
            //It allows him to preview a category before publishing
            if (!course.Published && !await _permissionService.Authorize(StandardPermissionProvider.ManageCourses, customer))
            {
                return(false);
            }

            //Check whether the current user purchased the course
            if (!await _mediator.Send(new GetCheckOrder()
            {
                Course = course, Customer = customer
            }) &&
                !await _permissionService.Authorize(StandardPermissionProvider.ManageCourses, customer))
            {
                return(false);
            }

            //ACL (access control list)
            if (!_aclService.Authorize(course, customer))
            {
                return(false);
            }

            //Store mapping
            if (!_storeMappingService.Authorize(course))
            {
                return(false);
            }

            return(true);
        }