Example #1
0
        public virtual IActionResult OfficialFeedSelect(OfficialFeedPluginSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedKendoGridJson());
            }

            //prepare model
            var model = _pluginModelFactory.PrepareOfficialFeedPluginListModel(searchModel);

            return(Json(model));
        }
        /// <summary>
        /// Prepare paged list model of plugins of the official feed
        /// </summary>
        /// <param name="searchModel">Search model of plugins of the official feed</param>
        /// <returns>List model of plugins of the official feed</returns>
        public virtual OfficialFeedPluginListModel PrepareOfficialFeedPluginListModel(OfficialFeedPluginSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get plugins
            var plugins = _officialFeedManager.GetAllPlugins(categoryId: searchModel.SearchCategoryId,
                                                             versionId: searchModel.SearchVersionId,
                                                             price: searchModel.SearchPriceId,
                                                             searchTerm: searchModel.SearchName,
                                                             pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new OfficialFeedPluginListModel().PrepareToGrid(searchModel, plugins, () =>
            {
                //fill in model values from the entity
                return(plugins?.Select(plugin => new OfficialFeedPluginModel
                {
                    Url = plugin.Url,
                    Name = plugin.Name,
                    CategoryName = plugin.Category,
                    SupportedVersions = plugin.SupportedVersions,
                    PictureUrl = plugin.PictureUrl,
                    Price = plugin.Price
                }) ?? new List <OfficialFeedPluginModel>());
            });

            return(model);
        }
 public PluginsConfigurationModel()
 {
     PluginsLocal        = new PluginSearchModel();
     AllPluginsAndThemes = new OfficialFeedPluginSearchModel();
 }
        /// <summary>
        /// Prepare search model of plugins of the official feed
        /// </summary>
        /// <param name="searchModel">Search model of plugins of the official feed</param>
        /// <returns>Search model of plugins of the official feed</returns>
        public virtual OfficialFeedPluginSearchModel PrepareOfficialFeedPluginSearchModel(OfficialFeedPluginSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare available versions
            var pluginVersions = _officialFeedManager.GetVersions();

            searchModel.AvailableVersions.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var version in pluginVersions)
            {
                searchModel.AvailableVersions.Add(new SelectListItem {
                    Text = version.Name, Value = version.Id.ToString()
                });
            }

            //pre-select current version
            //current version name and named on official site do not match. that's why we use "Contains"
            var currentVersionItem = searchModel.AvailableVersions.FirstOrDefault(x => x.Text.Contains(NopVersion.CurrentVersion));

            if (currentVersionItem != null)
            {
                searchModel.SearchVersionId = int.Parse(currentVersionItem.Value);
                currentVersionItem.Selected = true;
            }

            //prepare available plugin categories
            var pluginCategories = _officialFeedManager.GetCategories();

            searchModel.AvailableCategories.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var pluginCategory in pluginCategories)
            {
                var pluginCategoryNames = new List <string>();
                var tmpCategory         = pluginCategory;
                while (tmpCategory != null)
                {
                    pluginCategoryNames.Add(tmpCategory.Name);
                    tmpCategory = pluginCategories.FirstOrDefault(category => category.Id == tmpCategory.ParentCategoryId);
                }

                pluginCategoryNames.Reverse();

                searchModel.AvailableCategories.Add(new SelectListItem
                {
                    Value = pluginCategory.Id.ToString(),
                    Text  = string.Join(" >> ", pluginCategoryNames)
                });
            }

            //prepare available prices
            searchModel.AvailablePrices.Add(new SelectListItem
            {
                Value = "0",
                Text  = _localizationService.GetResource("Admin.Common.All")
            });
            searchModel.AvailablePrices.Add(new SelectListItem
            {
                Value = "10",
                Text  = _localizationService.GetResource("Admin.Configuration.Plugins.OfficialFeed.Price.Free")
            });
            searchModel.AvailablePrices.Add(new SelectListItem
            {
                Value = "20",
                Text  = _localizationService.GetResource("Admin.Configuration.Plugins.OfficialFeed.Price.Commercial")
            });

            //prepare page parameters
            searchModel.SetGridPageSize(15, "15");

            return(searchModel);
        }
Example #5
0
        /// <summary>
        /// Prepare paged list model of plugins of the official feed
        /// </summary>
        /// <param name="searchModel">Search model of plugins of the official feed</param>
        /// <returns>List model of plugins of the official feed</returns>
        public virtual OfficialFeedPluginListModel PrepareOfficialFeedPluginListModel(OfficialFeedPluginSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get plugins
            IPagedList <OfficialFeedPlugin> plugins = null;

            try
            {
                //ensure that no exception is thrown when www.nopcommerce.com website is not available
                plugins = _officialFeedManager.GetAllPlugins(categoryId: searchModel.SearchCategoryId,
                                                             versionId: searchModel.SearchVersionId,
                                                             price: searchModel.SearchPriceId,
                                                             searchTerm: searchModel.SearchName,
                                                             pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);
            }
            catch (Exception ex)
            {
                _logger.Error("No access to the list of plugins. Website www.nopcommerce.com is not available.", ex);
            }

            //prepare list model
            var model = new OfficialFeedPluginListModel
            {
                //fill in model values from the entity
                Data = plugins?.Select(plugin => new OfficialFeedPluginModel
                {
                    Url               = plugin.Url,
                    Name              = plugin.Name,
                    CategoryName      = plugin.Category,
                    SupportedVersions = plugin.SupportedVersions,
                    PictureUrl        = plugin.PictureUrl,
                    Price             = plugin.Price
                }) ?? new List <OfficialFeedPluginModel>(),
                Total = plugins?.TotalCount ?? 0
            };

            return(model);
        }