Exemple #1
0
        public async Task DeletePublicationsAsync(string[] ids)
        {
            using (var repository = _repositoryFactory())
            {
                await repository.RemoveContentPublicationsAsync(ids);

                await repository.UnitOfWork.CommitAsync();
            }

            DynamicContentPublicationCacheRegion.ExpireRegion();
        }
Exemple #2
0
        public async Task SavePublicationsAsync(DynamicContentPublication[] publications)
        {
            var pkMap          = new PrimaryKeyResolvingMap();
            var changedEntries = new List <GenericChangedEntry <DynamicContentPublication> >();

            using (var repository = _repositoryFactory())
            {
                var existEntities = await repository.GetContentPublicationsByIdsAsync(publications.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray());

                foreach (var publication in publications)
                {
                    SerializeDynamicContentPublicationConditions(publication);

                    var sourceEntity = AbstractTypeFactory <DynamicContentPublishingGroupEntity> .TryCreateInstance();

                    if (sourceEntity != null)
                    {
                        sourceEntity = sourceEntity.FromModel(publication, pkMap);
                        var targetEntity = existEntities.FirstOrDefault(x => x.Id == publication.Id);
                        if (targetEntity != null)
                        {
                            changedEntries.Add(new GenericChangedEntry <DynamicContentPublication>(publication, sourceEntity.ToModel(AbstractTypeFactory <DynamicContentPublication> .TryCreateInstance()), EntryState.Modified));
                            sourceEntity.Patch(targetEntity);
                        }
                        else
                        {
                            changedEntries.Add(new GenericChangedEntry <DynamicContentPublication>(publication, EntryState.Added));
                            repository.Add(sourceEntity);
                        }
                    }
                }
                await repository.UnitOfWork.CommitAsync();

                pkMap.ResolvePrimaryKeys();
                await _eventPublisher.Publish(new DynamicContentPublicationChangedEvent(changedEntries));
            }

            DynamicContentPublicationCacheRegion.ExpireRegion();
        }