/// <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);
        }
Esempio n. 2
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);
        }