/// <summary>
        /// Inserts catalogues
        /// </summary>
        /// <param name="catalogues">Catalogues</param>
        public virtual void InsertCatalogues(Catalogues catalogues)
        {
            if (catalogues == null)
                throw new ArgumentNullException("catalogues");

            _cataloguesRepository.Insert(catalogues);

            //cache
            _cacheManager.RemoveByPattern(CATALOGUES_PATTERN_KEY);
            _cacheManager.RemoveByPattern(NEWSCATALOGUES_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityInserted(catalogues);
        }
        /// <summary>
        /// Updates the catalogues
        /// </summary>
        /// <param name="catalogues">Catalogues</param>
        public virtual void UpdateCatalogues(Catalogues catalogues)
        {
            if (catalogues == null)
                throw new ArgumentNullException("catalogues");

            //validate catalogues hierarchy
            var parentCatalogues = GetCatalogueById(catalogues.ParentCatalogueId);
            while (parentCatalogues != null)
            {
                if (catalogues.Id == parentCatalogues.Id)
                {
                    catalogues.ParentCatalogueId = 0;
                    break;
                }
                parentCatalogues = GetCatalogueById(parentCatalogues.ParentCatalogueId);
            }

            _cataloguesRepository.Update(catalogues);

            //cache
            _cacheManager.RemoveByPattern(CATALOGUES_PATTERN_KEY);
            _cacheManager.RemoveByPattern(NEWSCATALOGUES_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityUpdated(catalogues);
        }
        /// <summary>
        /// Delete catalogues
        /// </summary>
        /// <param name="catalogues">Catalogues</param>
        public virtual void DeleteCatalogues(Catalogues catalogues)
        {
            if (catalogues == null)
                throw new ArgumentNullException("catalogues");

            catalogues.Deleted = true;
            UpdateCatalogues(catalogues);

            //reset a "Parent catalogues" property of all child subcategories
            var subcategories = GetAllCataloguesByParentCatalogueId(catalogues.Id, true);
            foreach (var subcatalogues in subcategories)
            {
                subcatalogues.ParentCatalogueId = 0;
                UpdateCatalogues(subcatalogues);
            }
        }
 protected virtual void UpdatePictureSeoNames(Catalogues catalogues)
 {
     var picture = _pictureService.GetPictureById(catalogues.PictureId);
     if (picture != null)
         _pictureService.SetSeoFilename(picture.Id, _pictureService.GetPictureSeName(catalogues.Name));
 }
        protected virtual void UpdateLocales(Catalogues catalogues, CataloguesModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                               x => x.Name,
                                                               localized.Name,
                                                               localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.Description,
                                                           localized.Description,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.MetaKeywords,
                                                           localized.MetaKeywords,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.MetaDescription,
                                                           localized.MetaDescription,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(catalogues,
                                                           x => x.MetaTitle,
                                                           localized.MetaTitle,
                                                           localized.LanguageId);

                //search engine name
                var seName = catalogues.ValidateSeName(localized.SeName, localized.Name, false);
                _urlRecordService.SaveSlug(catalogues, seName, localized.LanguageId);
            }
        }
 protected virtual void SaveCataloguesAcl(Catalogues catalogues, CataloguesModel model)
 {
     var existingAclRecords = _aclService.GetAclRecords(catalogues);
     var allCustomerRoles = _customerService.GetAllCustomerRoles(true);
     foreach (var customerRole in allCustomerRoles)
     {
         if (model.SelectedCustomerRoleIds != null && model.SelectedCustomerRoleIds.Contains(customerRole.Id))
         {
             //new role
             if (existingAclRecords.Count(acl => acl.CustomerRoleId == customerRole.Id) == 0)
                 _aclService.InsertAclRecord(catalogues, customerRole.Id);
         }
         else
         {
             //remove role
             var aclRecordToDelete = existingAclRecords.FirstOrDefault(acl => acl.CustomerRoleId == customerRole.Id);
             if (aclRecordToDelete != null)
                 _aclService.DeleteAclRecord(aclRecordToDelete);
         }
     }
 }
        protected virtual void PrepareAclModel(CataloguesModel model, Catalogues catalogues, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            model.AvailableCustomerRoles = _customerService
                .GetAllCustomerRoles(true)
                .Select(cr => cr.ToModel())
                .ToList();
            if (!excludeProperties)
            {
                if (catalogues != null)
                {
                    model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(catalogues);
                }
            }
        }