public async Task DeleteAsync(IEnumerable <string> ids, bool doDeleteValues = false)
        {
            using (var repository = _repositoryFactory())
            {
                var entities = await repository.GetPropertiesByIdsAsync(ids.ToArray());

                //Raise domain events before deletion
                var changedEntries = entities.Select(x => new GenericChangedEntry <Property>(x.ToModel(AbstractTypeFactory <Property> .TryCreateInstance()), EntryState.Deleted));

                await _eventPublisher.Publish(new PropertyChangingEvent(changedEntries));

                foreach (var entity in entities)
                {
                    repository.Remove(entity);
                    if (doDeleteValues)
                    {
                        await repository.RemoveAllPropertyValuesAsync(entity.Id);
                    }
                }
                await repository.UnitOfWork.CommitAsync();

                await _eventPublisher.Publish(new PropertyChangedEvent(changedEntries));

                //Reset catalog cache
                CatalogCacheRegion.ExpireRegion();
            }
        }
        public async Task SaveChangesAsync(IEnumerable <Property> properties)
        {
            var pkMap          = new PrimaryKeyResolvingMap();
            var changedEntries = new List <GenericChangedEntry <Property> >();

            ValidateProperties(properties);

            using (var repository = _repositoryFactory())
            {
                TryAddPredefinedValidationRules(properties);

                var dbExistProperties = await repository.GetPropertiesByIdsAsync(properties.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray());

                foreach (var property in properties)
                {
                    var modifiedEntity = AbstractTypeFactory <PropertyEntity> .TryCreateInstance().FromModel(property, pkMap);

                    var originalEntity = dbExistProperties.FirstOrDefault(x => x.Id == property.Id);

                    if (originalEntity != null)
                    {
                        changedEntries.Add(new GenericChangedEntry <Property>(property, originalEntity.ToModel(AbstractTypeFactory <Property> .TryCreateInstance()), EntryState.Modified));
                        modifiedEntity.Patch(originalEntity);
                        //Force set ModifiedDate property to mark a product changed. Special for  partial update cases when product table not have changes
                        originalEntity.ModifiedDate = DateTime.UtcNow;
                    }
                    else
                    {
                        repository.Add(modifiedEntity);
                        changedEntries.Add(new GenericChangedEntry <Property>(property, EntryState.Added));
                    }
                }

                //Raise domain events
                await _eventPublisher.Publish(new PropertyChangingEvent(changedEntries));

                //Save changes in database
                await repository.UnitOfWork.CommitAsync();

                pkMap.ResolvePrimaryKeys();

                //Reset catalog cache
                CatalogCacheRegion.ExpireRegion();

                await _eventPublisher.Publish(new PropertyChangedEvent(changedEntries));
            }
        }
Beispiel #3
0
        public void Delete(IEnumerable <string> catalogIds)
        {
            var catalogs = GetByIds(catalogIds);
            //Raise domain events before deletion
            var changedEntries = catalogs.Select(x => new GenericChangedEntry <Catalog>(x, EntryState.Deleted));

            _eventPublisher.Publish(new CatalogChangingEvent(changedEntries));
            using (var repository = _repositoryFactory())
            {
                //TODO:  raise events on catalog deletion
                repository.RemoveCatalogs(catalogIds.ToArray());
                repository.UnitOfWork.Commit();
                //Reset cached catalogs and catalogs
                CatalogCacheRegion.ExpireRegion();
            }
            _eventPublisher.Publish(new CatalogChangedEvent(changedEntries));
        }
        public virtual async Task DeleteAsync(string[] categoryIds)
        {
            var categories = await GetByIdsAsync(categoryIds, CategoryResponseGroup.Info.ToString());

            var changedEntries = categories
                                 .Select(c => new GenericChangedEntry <Category>(c, EntryState.Deleted))
                                 .ToList();

            using (var repository = _repositoryFactory())
            {
                await _eventPublisher.Publish(new CategoryChangingEvent(changedEntries));

                await repository.RemoveCategoriesAsync(categoryIds);

                await repository.UnitOfWork.CommitAsync();

                CatalogCacheRegion.ExpireRegion();
                await _eventPublisher.Publish(new CategoryChangedEvent(changedEntries));
            }
        }
Beispiel #5
0
        public virtual async Task DeleteAsync(string[] catalogIds)
        {
            using (var repository = _repositoryFactory())
            {
                var catalogs = await GetByIdsAsync(catalogIds);

                if (!catalogs.IsNullOrEmpty())
                {
                    var changedEntries = catalogs.Select(x => new GenericChangedEntry <Catalog>(x, EntryState.Deleted));
                    await _eventPublisher.Publish(new CatalogChangingEvent(changedEntries));

                    await repository.RemoveCatalogsAsync(catalogs.Select(m => m.Id).ToArray());

                    await repository.UnitOfWork.CommitAsync();

                    await _eventPublisher.Publish(new CatalogChangedEvent(changedEntries));
                }
            }
            CatalogCacheRegion.ExpireRegion();
        }
        public ActionResult ResetCache()
        {
            //TODO: Replace to some other (maybe with using reflection)
            ThemeEngineCacheRegion.ExpireRegion();
            CartCacheRegion.ExpireRegion();
            CatalogCacheRegion.ExpireRegion();
            ContentBlobCacheRegion.ExpireRegion();
            CustomerCacheRegion.ExpireRegion();
            MarketingCacheRegion.ExpireRegion();
            PricingCacheRegion.ExpireRegion();
            QuoteCacheRegion.ExpireRegion();
            RecommendationsCacheRegion.ExpireRegion();
            StaticContentCacheRegion.ExpireRegion();
            StoreCacheRegion.ExpireRegion();
            TaxCacheRegion.ExpireRegion();
            SubscriptionCacheRegion.ExpireRegion();
            SecurityCacheRegion.ExpireRegion();

            return(StoreFrontRedirect("~/"));
        }
Beispiel #7
0
        public virtual void SaveChanges(IEnumerable <Category> categories)
        {
            var pkMap          = new PrimaryKeyResolvingMap();
            var changedEntries = new List <GenericChangedEntry <Category> >();

            ValidateCategoryProperties(categories);

            using (var repository = _repositoryFactory())
            {
                var dbExistCategories = repository.GetCategoriesByIds(categories.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray());
                foreach (var category in categories)
                {
                    var originalEntity = dbExistCategories.FirstOrDefault(x => x.Id == category.Id);
                    var modifiedEntity = AbstractTypeFactory <CategoryEntity> .TryCreateInstance().FromModel(category, pkMap);

                    if (originalEntity != null)
                    {
                        changedEntries.Add(new GenericChangedEntry <Category>(category, originalEntity.ToModel(AbstractTypeFactory <Category> .TryCreateInstance()), EntryState.Modified));
                        modifiedEntity.Patch(originalEntity);
                        //Force set ModifiedDate property to mark a product changed. Special for  partial update cases when product table not have changes
                        originalEntity.ModifiedDate = DateTime.UtcNow;
                    }
                    else
                    {
                        repository.Add(modifiedEntity);
                        changedEntries.Add(new GenericChangedEntry <Category>(category, EntryState.Added));
                    }
                }

                //Raise domain events
                _eventPublisher.Publish(new CategoryChangingEvent(changedEntries));
                //Save changes in database
                repository.UnitOfWork.Commit();
                pkMap.ResolvePrimaryKeys();
                _eventPublisher.Publish(new CategoryChangedEvent(changedEntries));
                //Reset catalog cache
                CatalogCacheRegion.ExpireRegion();
            }
            //Need add seo separately
            _seoService.SaveSeoForObjectsAsync(categories.OfType <ISeoSupport>().ToArray());
        }
        public virtual async Task SaveChangesAsync(Catalog[] catalogs)
        {
            var pkMap          = new PrimaryKeyResolvingMap();
            var changedEntries = new List <GenericChangedEntry <Catalog> >();

            using (var repository = _repositoryFactory())
            {
                await ValidateCatalogPropertiesAsync(catalogs);

                var dbExistEntities = await repository.GetCatalogsByIdsAsync(catalogs.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray());

                foreach (var catalog in catalogs)
                {
                    var originalEntity = dbExistEntities.FirstOrDefault(x => x.Id == catalog.Id);
                    var modifiedEntity = AbstractTypeFactory <CatalogEntity> .TryCreateInstance().FromModel(catalog, pkMap);

                    if (originalEntity != null)
                    {
                        changedEntries.Add(new GenericChangedEntry <Catalog>(catalog, originalEntity.ToModel(AbstractTypeFactory <Catalog> .TryCreateInstance()), EntryState.Modified));
                        modifiedEntity.Patch(originalEntity);
                    }
                    else
                    {
                        repository.Add(modifiedEntity);
                        changedEntries.Add(new GenericChangedEntry <Catalog>(catalog, EntryState.Added));
                    }
                }
                //Raise domain events
                await _eventPublisher.Publish(new CatalogChangingEvent(changedEntries));

                //Save changes in database
                await repository.UnitOfWork.CommitAsync();

                pkMap.ResolvePrimaryKeys();

                //Reset cached catalogs and catalogs
                CatalogCacheRegion.ExpireRegion();

                await _eventPublisher.Publish(new CatalogChangedEvent(changedEntries));
            }
        }
        public virtual async Task SaveChangesAsync(Category[] categories)
        {
            var pkMap          = new PrimaryKeyResolvingMap();
            var changedEntries = new List <GenericChangedEntry <Category> >();

            await ValidateCategoryPropertiesAsync(categories);

            using (var repository = _repositoryFactory())
            {
                var dbExistCategories = await repository.GetCategoriesByIdsAsync(categories.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray(), CategoryResponseGroup.Full);

                foreach (var category in categories)
                {
                    var originalEntity = dbExistCategories.FirstOrDefault(x => x.Id == category.Id);
                    var modifiedEntity = AbstractTypeFactory <CategoryEntity> .TryCreateInstance().FromModel(category, pkMap);

                    if (originalEntity != null)
                    {
                        changedEntries.Add(new GenericChangedEntry <Category>(category, originalEntity.ToModel(AbstractTypeFactory <Category> .TryCreateInstance()), EntryState.Modified));
                        modifiedEntity.Patch(originalEntity);
                        //Force set ModifiedDate property to mark a product changed. Special for  partial update cases when product table not have changes
                        originalEntity.ModifiedDate = DateTime.UtcNow;
                    }
                    else
                    {
                        repository.Add(modifiedEntity);
                        changedEntries.Add(new GenericChangedEntry <Category>(category, EntryState.Added));
                    }
                }

                await _eventPublisher.Publish(new CategoryChangingEvent(changedEntries));

                await repository.UnitOfWork.CommitAsync();

                pkMap.ResolvePrimaryKeys();
                CatalogCacheRegion.ExpireRegion();

                await _eventPublisher.Publish(new CategoryChangedEvent(changedEntries));
            }
        }
Beispiel #10
0
 protected virtual void ClearCache(IEnumerable <Category> categories)
 {
     CatalogCacheRegion.ExpireRegion();
     SeoInfoCacheRegion.ExpireRegion();
 }