Example #1
0
        public IList <BookDir> GetBookDirBreadCrumb(BookDir bookDir, IList <BookDir> allBookDirs = null, bool showHidden = false)
        {
            if (bookDir == null)
            {
                throw new ArgumentNullException(nameof(bookDir));
            }

            var result = new List <BookDir>();

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

            while (bookDir != null &&                                 //not null
                   !bookDir.Deleted &&                                //not deleted
                   (showHidden || bookDir.Published) &&               //published
                   (showHidden || _aclService.Authorize(bookDir)) &&  //ACL
                                                                      // (showHidden || _storeMappingService.Authorize(bookDir)) && //Store mapping
                   !alreadyProcessedCategoryIds.Contains(bookDir.Id)) //prevent circular references
            {
                result.Add(bookDir);
                alreadyProcessedCategoryIds.Add(bookDir.Id);
                bookDir = allBookDirs != null?allBookDirs.FirstOrDefault(c => c.Id == bookDir.ParentBookDirId)
                              : GetBookDirById(bookDir.ParentBookDirId);
            }
            result.Reverse();
            return(result);
            // return new List<BookDir>();
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bookdir"></param>
        /// <returns></returns>
        public int UpdateBookDir(BookDir bookdir)
        {
            try
            {
                if (bookdir == null)
                {
                    throw new ArgumentNullException(nameof(bookdir));
                }

                if (bookdir is IEntityForCaching)
                {
                    throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
                }
                _bookdirRepository.Update(bookdir);
                _cacheManager.RemoveByPattern(NopBookDirDefault.BookDirsPrefixCacheKey);
                //event notification
                _eventPublisher.EntityUpdated(bookdir);
                return(1);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex, _workContext.CurrentCustomer);
                return(0);
            }
        }
Example #3
0
        public string GetFormattedBreadCrumb(BookDir bookDir, IList <BookDir> allBookDirs = null,
                                             string separator = ">>", int languageId = 0)
        {
            var result     = string.Empty;
            var breadcrumb = GetBookDirBreadCrumb(bookDir, allBookDirs, true);

            for (var i = 0; i <= breadcrumb.Count - 1; i++)
            {
                var categoryName = _localizationService.GetLocalized(breadcrumb[i], x => x.Name, languageId);
                result = string.IsNullOrEmpty(result) ? categoryName : $"{result} {separator} {categoryName}";
            }
            return(result);
        }
Example #4
0
        public int DeleteBookDir(BookDir store)
        {
            try
            {
                if (store == null)
                {
                    throw new ArgumentNullException(nameof(store));
                }

                if (store is IEntityForCaching)
                {
                    throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
                }

                var allStores = GetAllBookDirs();
                if (allStores.Count == 1)
                {
                    throw new Exception("You cannot delete the only configured BookDir");
                }

                _bookdirRepository.Delete(store);

                _cacheManager.RemoveByPattern(NopBookDirDefault.BookDirsPrefixCacheKey);

                //event notification
                _eventPublisher.EntityDeleted(store);

                return(1);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex, _workContext.CurrentCustomer);


                return(0);
            }
        }
Example #5
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);
        }