Example #1
0
        public AiBookModelView PrepareBookNodeModel(AiBookModelView bookModelModel, int?filterByBookId)
        {
            var model = new AiBookModel();

            if (bookModelModel == null)
            {
                throw new ArgumentNullException(nameof(bookModelModel));
            }

            Action <AiBookModelLocalizedModel, int> localizedModelConfiguration = null;

            //prepare nested search models
            //Prepare Categories
            _baseAdminModelFactory.PrepareCategories(bookModelModel.AvailableCategories,
                                                     defaultItemText: _localizationService.GetResource("Admin.Catalog.Categories.Fields.Parent.None"));
            if (bookModelModel.BookDirId > 0)
            {
                var bookdir = _bookdirService.GetBookDirById(bookModelModel.BookDirId);
                if (bookdir != null)
                {
                    bookModelModel.BookId = bookdir.BookID;
                }
                bookModelModel.AvailableBookDirs = SelectListHelper.GetBookDirList(_bookdirService, _workContext.CurrentCustomer, _cacheManager);
            }


            if (bookModelModel.BookId > 0)
            {
                var result = _productService.GetProductById(bookModelModel.BookId);
                if (result != null)
                {
                    if (result.ProductCategories != null)
                    {
                        bookModelModel.CateId = result.ProductCategories.FirstOrDefault().CategoryId;
                    }
                    bookModelModel.BookId         = result.Id;
                    bookModelModel.AvailableBooks = SelectListHelper.GetBookList(_productService, new List <int> {
                        bookModelModel.CateId
                    }, _workContext.CurrentCustomer, _cacheManager);
                }
            }


            localizedModelConfiguration = (locale, languageId) =>
            {
                locale.Name        = _localizationService.GetLocalized(model, entity => entity.Name, languageId, false, false);
                locale.Desc        = _localizationService.GetLocalized(model, entity => entity.Desc, languageId, false, false);
                locale.WebModelUrl = _localizationService.GetLocalized(model, entity => entity.WebModelUrl, languageId, false, false);
                locale.WebGltfUrl  = _localizationService.GetLocalized(model, entity => entity.WebGltfUrl, languageId, false, false);
                locale.WebBinUrl   = _localizationService.GetLocalized(model, entity => entity.WebBinUrl, languageId, false, false);
                locale.AbUrl       = _localizationService.GetLocalized(model, entity => entity.AbUrl, languageId, false, false);
                locale.ImgUrl      = _localizationService.GetLocalized(model, entity => entity.ImgUrl, languageId, false, false);
                locale.StrJson     = _localizationService.GetLocalized(model, entity => entity.StrJson, languageId, false, false);
                //locale.SeName = _urlRecordService.GetSeName(category, languageId, false, false);
            };


            bookModelModel.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            return(bookModelModel);
        }
        /// <summary>
        /// Prepare category model
        /// </summary>
        /// <param name="model">Category model</param>
        /// <param name="category">Category</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Category model</returns>
        public virtual CategoryModel PrepareCategoryModel(CategoryModel model, Category category, bool excludeProperties = false)
        {
            Action <CategoryLocalizedModel, int> localizedModelConfiguration = null;

            if (category != null)
            {
                //fill in model values from the entity
                model = model ?? category.ToModel <CategoryModel>();

                //prepare nested search model
                PrepareCategoryProductSearchModel(model.CategoryProductSearchModel, category);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name            = _localizationService.GetLocalized(category, entity => entity.Name, languageId, false, false);
                    locale.Description     = _localizationService.GetLocalized(category, entity => entity.Description, languageId, false, false);
                    locale.MetaKeywords    = _localizationService.GetLocalized(category, entity => entity.MetaKeywords, languageId, false, false);
                    locale.MetaDescription = _localizationService.GetLocalized(category, entity => entity.MetaDescription, languageId, false, false);
                    locale.MetaTitle       = _localizationService.GetLocalized(category, entity => entity.MetaTitle, languageId, false, false);
                    locale.SeName          = _urlRecordService.GetSeName(category, languageId, false, false);
                };
            }

            //set default values for the new model
            if (category == null)
            {
                model.PageSize         = _catalogSettings.DefaultCategoryPageSize;
                model.PageSizeOptions  = _catalogSettings.DefaultCategoryPageSizeOptions;
                model.Published        = true;
                model.IncludeInTopMenu = true;
                model.AllowCustomersToSelectPageSize = true;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare available category templates
            _baseAdminModelFactory.PrepareCategoryTemplates(model.AvailableCategoryTemplates, false);

            //prepare available parent categories
            _baseAdminModelFactory.PrepareCategories(model.AvailableCategories,
                                                     defaultItemText: _localizationService.GetResource("Admin.Catalog.Categories.Fields.Parent.None"));

            //prepare model discounts
            var availableDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, showHidden: true);

            _discountSupportedModelFactory.PrepareModelDiscounts(model, category, availableDiscounts, excludeProperties);

            //prepare model customer roles
            _aclSupportedModelFactory.PrepareModelCustomerRoles(model, category, excludeProperties);

            //prepare model stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, category, excludeProperties);

            return(model);
        }
        /// <summary>
        /// Prepare product search model
        /// </summary>
        /// <param name="searchModel">Product search model</param>
        /// <returns>Product search model</returns>
        public virtual QuestionSearchModel PrepareQuestionSearchModel(QuestionSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare available categories
            _baseAdminModelFactory.PrepareCategories(searchModel.AvailableCategories);

            //prepare available product types
            _baseAdminModelFactory.PrepareQuestionTypes(searchModel.AvailableQuestionTypes);

            //prepare "published" filter (0 - all; 1 - published only; 2 - unpublished only)
            searchModel.AvailablePublishedOptions.Add(new SelectListItem
            {
                Value = "0",
                Text  = "All"
            });
            searchModel.AvailablePublishedOptions.Add(new SelectListItem
            {
                Value = "1",
                Text  = "Published only"
            });
            searchModel.AvailablePublishedOptions.Add(new SelectListItem
            {
                Value = "2",
                Text  = "Unpublished only"
            });

            //prepare grid
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Example #4
0
        /// <summary>
        /// Prepare news item search model
        /// </summary>
        /// <param name="searchModel">News item search model</param>
        /// <returns>News item search model</returns>
        public virtual NewsItemSearchModel PrepareNewsItemSearchModel(NewsItemSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            _baseAdminModelFactory.PrepareCategories(searchModel.AvailableCategories, true, "Kategori Seçiniz");
            _baseAdminModelFactory.PrepareEditorList(searchModel.AvailableEditor, true, "Editör Seçebilirsiniz");

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Example #5
0
        /// <summary>
        /// Prepare customer role product search model
        /// </summary>
        /// <param name="searchModel">Customer role product search model</param>
        /// <returns>Customer role product search model</returns>
        public virtual CustomerRoleProductSearchModel PrepareCustomerRoleProductSearchModel(CustomerRoleProductSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //a vendor should have access only to his products
            searchModel.IsLoggedInAsVendor = _workContext.CurrentVendor != null;

            //prepare available categories
            _baseAdminModelFactory.PrepareCategories(searchModel.AvailableCategories);

            //prepare available manufacturers
            _baseAdminModelFactory.PrepareManufacturers(searchModel.AvailableManufacturers);

            //prepare available stores
            _baseAdminModelFactory.PrepareStores(searchModel.AvailableStores);

            //prepare available vendors
            _baseAdminModelFactory.PrepareVendors(searchModel.AvailableVendors);

            //prepare available product types
            _baseAdminModelFactory.PrepareProductTypes(searchModel.AvailableProductTypes);

            //prepare page parameters
            searchModel.SetPopupGridPageSize();

            return(searchModel);
        }
        /// <summary>
        /// Prepare product search model to add to the manufacturer
        /// </summary>
        /// <param name="searchModel">Product search model to add to the manufacturer</param>
        /// <returns>Product search model to add to the manufacturer</returns>
        public virtual AddProductToManufacturerSearchModel PrepareAddProductToManufacturerSearchModel(AddProductToManufacturerSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare available categories
            _baseAdminModelFactory.PrepareCategories(searchModel.AvailableCategories);

            //prepare available manufacturers
            _baseAdminModelFactory.PrepareManufacturers(searchModel.AvailableManufacturers);

            //prepare available stores
            _baseAdminModelFactory.PrepareStores(searchModel.AvailableStores);

            //prepare available vendors
            _baseAdminModelFactory.PrepareVendors(searchModel.AvailableVendors);

            //prepare available product types
            _baseAdminModelFactory.PrepareProductTypes(searchModel.AvailableProductTypes);

            //prepare page parameters
            searchModel.SetPopupGridPageSize();

            return(searchModel);
        }
Example #7
0
        /// <summary>
        /// Prepare category model
        /// </summary>
        /// <param name="model">Category model</param>
        /// <param name="category">Category</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Category model</returns>
        public virtual CategoryModel PrepareCategoryModel(CategoryModel model, Category category, bool excludeProperties = false)
        {
            if (category != null)
            {
                //fill in model values from the entity
                model = model ?? category.ToModel <CategoryModel>();
            }

            //set default values for the new model
            if (category == null)
            {
                model.Published           = true;
                model.IncludeInTopMenu    = true;
                model.IncludeInFooterMenu = false;
                model.IncludeInManset     = false;
            }



            //prepare available category templates
            _baseAdminModelFactory.PrepareCategoryTemplates(model.AvailableCategoryTemplates, false);

            //prepare available parent categories
            _baseAdminModelFactory.PrepareCategories(model.AvailableCategories,
                                                     defaultItemText: "Kategori Seç");
            _baseAdminModelFactory.PrepareSliders(model.AvailableSliders, true, "Slider Seçebiliirsiniz");
            _baseAdminModelFactory.PreparePhotoGalleries(model.AvailablePhotoGallery, true, "Galeri Sçebilirsiniz");
            _baseAdminModelFactory.PrepareVideoGalleries(model.AvailableVideoGalleries, true, "Video Galeri Seçebilirsiniz");

            return(model);
        }
Example #8
0
        /// <summary>
        /// Prepare product search model
        /// </summary>
        /// <param name="searchModel">Product search model</param>
        /// <returns>Product search model</returns>
        public virtual ProductSearchModel PrepareProductSearchModel(ProductSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //a vendor should have access only to his products
            searchModel.IsLoggedInAsVendor           = _workContext.CurrentVendor != null;
            searchModel.AllowVendorsToImportProducts = _vendorSettings.AllowVendorsToImportProducts;

            //prepare available categories
            _baseAdminModelFactory.PrepareCategories(searchModel.AvailableCategories);

            //prepare available stores
            _baseAdminModelFactory.PrepareStores(searchModel.AvailableStores);

            //prepare available vendors
            _baseAdminModelFactory.PrepareVendors(searchModel.AvailableVendors);

            //prepare available product types
            _baseAdminModelFactory.PrepareProductTypes(searchModel.AvailableProductTypes);

            //prepare "published" filter (0 - all; 1 - published only; 2 - unpublished only)
            searchModel.AvailablePublishedOptions.Add(new SelectListItem
            {
                Value = "0",
                Text  = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.All")
            });
            searchModel.AvailablePublishedOptions.Add(new SelectListItem
            {
                Value = "1",
                Text  = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.PublishedOnly")
            });
            searchModel.AvailablePublishedOptions.Add(new SelectListItem
            {
                Value = "2",
                Text  = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.UnpublishedOnly")
            });

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
        /// <summary>
        /// Prepare category model
        /// </summary>
        /// <param name="model">Category model</param>
        /// <param name="category">Category</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Category model</returns>
        public virtual CategoryModel PrepareCategoryModel(CategoryModel model, Category category, bool excludeProperties = false)
        {
            if (category != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model = category.ToModel <CategoryModel>();
                }

                //prepare nested search model
                PrepareCategoryQuestionSearchModel(model.CategoryQuestionSearchModel, category);
            }

            //prepare available parent categories
            _baseAdminModelFactory.PrepareCategories(model.AvailableCategories,
                                                     defaultItemText: "[None]");

            return(model);
        }
        /// <summary>
        /// Prepare bestseller search model
        /// </summary>
        /// <param name="searchModel">Bestseller search model</param>
        /// <returns>Bestseller search model</returns>
        public virtual BestsellerSearchModel PrepareBestsellerSearchModel(BestsellerSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            searchModel.IsLoggedInAsVendor = _workContext.CurrentVendor != null;

            //prepare available stores
            _baseAdminModelFactory.PrepareStores(searchModel.AvailableStores);

            //prepare available order statuses
            _baseAdminModelFactory.PrepareOrderStatuses(searchModel.AvailableOrderStatuses);

            //prepare available payment statuses
            _baseAdminModelFactory.PreparePaymentStatuses(searchModel.AvailablePaymentStatuses);

            //prepare available categories
            _baseAdminModelFactory.PrepareCategories(searchModel.AvailableCategories);

            //prepare available manufacturers
            _baseAdminModelFactory.PrepareManufacturers(searchModel.AvailableManufacturers);

            //prepare available billing countries
            searchModel.AvailableCountries = _countryService.GetAllCountriesForBilling(showHidden: true)
                                             .Select(country => new SelectListItem {
                Text = country.Name, Value = country.Id.ToString()
            }).ToList();
            searchModel.AvailableCountries.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });

            //prepare available vendors
            _baseAdminModelFactory.PrepareVendors(searchModel.AvailableVendors);

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Example #11
0
        public BookDirModel PrepareBookDirModel(BookDirModel model, BookDir bookdir = null, bool excludeProperties = false)
        {
            Action <BookDirLocalizedModel, int> localizedModelConfiguration = null;

            if (bookdir != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model        = bookdir.ToModel <BookDirModel>();
                    model.SeName = _urlRecordService.GetSeName(bookdir, 0, true, false);
                }
                var result = _productService.GetProductById(bookdir.BookID);
                if (result != null)
                {
                    if (result.ProductCategories != null)
                    {
                        model.CategryID = result.ProductCategories.FirstOrDefault().CategoryId;
                    }
                    model.BookID = result.Id;
                    var products = _productService.SearchProducts(showHidden: true,
                                                                  categoryIds: new List <int>()
                    {
                        model.CategryID
                    },
                                                                  manufacturerId: 0,
                                                                  storeId: 0,
                                                                  vendorId: 0,
                                                                  warehouseId: 0,
                                                                  productType: null,
                                                                  keywords: null,
                                                                  pageIndex: 0,
                                                                  pageSize: int.MaxValue);

                    // model.BookList = products.ToList().ToSelect<Product>()
                }
                //prepare nested search model

                // PrepareBookDirSearchModel()

                //  PrepareCategoryProductSearchModel(model.CategoryProductSearchModel, category);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name            = _localizationService.GetLocalized(bookdir, entity => entity.Name, languageId, false, false);
                    locale.Description     = _localizationService.GetLocalized(bookdir, entity => entity.Description, languageId, false, false);
                    locale.MetaKeywords    = _localizationService.GetLocalized(bookdir, entity => entity.MetaKeywords, languageId, false, false);
                    locale.MetaDescription = _localizationService.GetLocalized(bookdir, entity => entity.MetaDescription, languageId, false, false);
                    //locale.MetaTitle = _localizationService.GetLocalized(category, entity => entity.MetaTitle, languageId, false, false);
                    //locale.SeName = _urlRecordService.GetSeName(category, languageId, false, false);
                };
            }

            //set default values for the new model
            if (bookdir == null)
            {
                if (model == null)
                {
                    model = new BookDirModel();
                }

                //model.PageSize = _catalogSettings.DefaultCategoryPageSize;
                // model.PageSizeOptions = _catalogSettings.DefaultCategoryPageSizeOptions;
                model.Published = true;
                //  model.IncludeInTopMenu = true;
                model.AllowCustomersToSelectPageSize = true;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare available category templates
            // _baseAdminModelFactory.PrepareCategoryTemplates(model.AvailableCategoryTemplates, false);
            //prepare available parent categories
            _baseAdminModelFactory.PrepareCategories(model.AvailableCategories,
                                                     defaultItemText: _localizationService.GetResource("Admin.Catalog.Categories.Fields.Parent.None"));
            //prepare model discounts
            // var availableDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, showHidden: true);
            //_discountSupportedModelFactory.PrepareModelDiscounts(model, category, availableDiscounts, excludeProperties);
            //prepare model customer roles
            _aclSupportedModelFactory.PrepareModelCustomerRoles(model, bookdir, excludeProperties);
            //prepare model stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, bookdir, excludeProperties);
            return(model);
        }