Esempio n. 1
0
 public virtual async Task Handle(StoreChangedEvent message)
 {
     foreach (var changedEntry in message.ChangedEntries)
     {
         if (changedEntry.EntryState == EntryState.Added)
         {
             var taskUpsertSeoForObjects       = _seoService.SaveSeoForObjectsAsync(new[] { changedEntry.NewEntry });
             var taskSaveDynamicPropertyValues = _dynamicPropertyService.SaveDynamicPropertyValuesAsync(changedEntry.NewEntry);
             var taskSaveEntitySettingsValues  = _settingManager.DeepSaveSettingsAsync(changedEntry.NewEntry);
             await Task.WhenAll(taskUpsertSeoForObjects, taskSaveDynamicPropertyValues, taskSaveEntitySettingsValues);
         }
         else if (changedEntry.EntryState == EntryState.Modified)
         {
             var taskUpsertSeoForObjects       = _seoService.SaveSeoForObjectsAsync(new[] { changedEntry.NewEntry });
             var taskSaveDynamicPropertyValues = _dynamicPropertyService.SaveDynamicPropertyValuesAsync(changedEntry.NewEntry);
             var taskSaveEntitySettingsValues  = _settingManager.DeepSaveSettingsAsync(changedEntry.NewEntry);
             await Task.WhenAll(taskUpsertSeoForObjects, taskSaveDynamicPropertyValues, taskSaveEntitySettingsValues);
         }
         else if (changedEntry.EntryState == EntryState.Deleted)
         {
             var taskDeleteSeoForObject          = _seoService.DeleteSeoForObjectAsync(changedEntry.NewEntry);
             var taskDeleteDynamicPropertyValues = _dynamicPropertyService.DeleteDynamicPropertyValuesAsync(changedEntry.NewEntry);
             var taskRemoveEntitySettingsValues  = _settingManager.DeepRemoveSettingsAsync(changedEntry.NewEntry);
             await Task.WhenAll(taskDeleteSeoForObject, taskDeleteDynamicPropertyValues, taskRemoveEntitySettingsValues);
         }
     }
 }
Esempio n. 2
0
        public async Task Handle(MemberChangedEvent message)
        {
            foreach (var changedEntry in message.ChangedEntries)
            {
                if (changedEntry.EntryState == EntryState.Added)
                {
                    await _dynamicPropertyService.SaveDynamicPropertyValuesAsync(changedEntry.NewEntry);

                    if (changedEntry.NewEntry is ISeoSupport seoSupport)
                    {
                        await _seoService.SaveSeoForObjectsAsync(new[] { seoSupport });
                    }
                }
                else if (changedEntry.EntryState == EntryState.Modified)
                {
                    await _dynamicPropertyService.SaveDynamicPropertyValuesAsync(changedEntry.NewEntry);

                    if (changedEntry.NewEntry is ISeoSupport seoSupport)
                    {
                        await _seoService.SaveSeoForObjectsAsync(new[] { seoSupport });
                    }
                }
                else if (changedEntry.EntryState == EntryState.Deleted)
                {
                    await _dynamicPropertyService.DeleteDynamicPropertyValuesAsync(changedEntry.NewEntry);

                    if (changedEntry.NewEntry is ISeoSupport seoSupport)
                    {
                        await _seoService.DeleteSeoForObjectAsync(seoSupport);
                    }
                }
            }
        }
Esempio n. 3
0
 public virtual async Task Handle(CartChangedEvent message)
 {
     foreach (var changedEntry in message.ChangedEntries)
     {
         if (changedEntry.EntryState == EntryState.Added)
         {
             await _dynamicPropertyService.SaveDynamicPropertyValuesAsync(changedEntry.NewEntry);
         }
         else if (changedEntry.EntryState == EntryState.Modified)
         {
             await _dynamicPropertyService.SaveDynamicPropertyValuesAsync(changedEntry.NewEntry);
             await TryDeleteDynamicPropertiesForRemovedLineItems(changedEntry);
         }
         else if (changedEntry.EntryState == EntryState.Deleted)
         {
             await _dynamicPropertyService.DeleteDynamicPropertyValuesAsync(changedEntry.NewEntry);
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Create or update members in database
        /// </summary>
        /// <param name="members"></param>
        public virtual async Task SaveChangesAsync(Member[] members)
        {
            var pkMap          = new PrimaryKeyResolvingMap();
            var changedEntries = new List <GenericChangedEntry <Member> >();

            using (var repository = _repositoryFactory())
            {
                var existingMemberEntities = await repository.GetMembersByIdsAsync(members.Where(m => !m.IsTransient()).Select(m => m.Id).ToArray());

                foreach (var member in members)
                {
                    var memberEntityType = AbstractTypeFactory <Member> .AllTypeInfos.Where(t => t.MappedType != null && t.IsAssignableTo(member.MemberType)).Select(t => t.MappedType).FirstOrDefault();

                    if (memberEntityType != null)
                    {
                        var dataSourceMember = AbstractTypeFactory <MemberEntity> .TryCreateInstance(memberEntityType.Name);

                        if (dataSourceMember != null)
                        {
                            dataSourceMember.FromModel(member, pkMap);

                            var dataTargetMember = existingMemberEntities.FirstOrDefault(m => m.Id == member.Id);
                            if (dataTargetMember != null)
                            {
                                changedEntries.Add(new GenericChangedEntry <Member>(member, dataTargetMember.ToModel(AbstractTypeFactory <Member> .TryCreateInstance(member.MemberType)), EntryState.Modified));
                                dataSourceMember.Patch(dataTargetMember);
                            }
                            else
                            {
                                repository.Add(dataSourceMember);
                                changedEntries.Add(new GenericChangedEntry <Member>(member, EntryState.Added));
                            }
                        }
                    }
                }
                //Raise domain events
                await _eventPublisher.Publish(new MemberChangingEvent(changedEntries));

                await repository.UnitOfWork.CommitAsync();

                pkMap.ResolvePrimaryKeys();

                foreach (var member in members)
                {
                    await _dynamicPropertyService.SaveDynamicPropertyValuesAsync(member);
                }

                await _eventPublisher.Publish(new MemberChangedEvent(changedEntries));
            }

            ClearCache(members);
        }
Esempio n. 5
0
        public virtual async Task SaveChangesAsync(CustomerOrder[] orders)
        {
            var pkMap          = new PrimaryKeyResolvingMap();
            var changedEntries = new List <GenericChangedEntry <CustomerOrder> >();

            using (var repository = _repositoryFactory())
            {
                var dataExistOrders = await repository.GetCustomerOrdersByIdsAsync(orders.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray(), CustomerOrderResponseGroup.Full);

                foreach (var order in orders)
                {
                    await EnsureThatAllOperationsHaveNumber(order);

                    LoadOrderDependencies(order);

                    var originalEntity = dataExistOrders.FirstOrDefault(x => x.Id == order.Id);
                    //Calculate order totals
                    _totalsCalculator.CalculateTotals(order);

                    var modifiedEntity = AbstractTypeFactory <CustomerOrderEntity> .TryCreateInstance()
                                         .FromModel(order, pkMap) as CustomerOrderEntity;

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

                await repository.UnitOfWork.CommitAsync();

                pkMap.ResolvePrimaryKeys();
            }

            //Save dynamic properties
            foreach (var order in orders)
            {
                await _dynamicPropertyService.SaveDynamicPropertyValuesAsync(order);
            }
            //Raise domain events
            await _eventPublisher.Publish(new OrderChangedEvent(changedEntries));

            ClearCache(orders);
        }
Esempio n. 6
0
        public async Task Handle(DynamicContentItemChangedEvent message)
        {
            foreach (var changedEntry in message.ChangedEntries)
            {
                switch (changedEntry.EntryState)
                {
                case EntryState.Added:
                case EntryState.Modified:
                    await _dynamicPropertyService.SaveDynamicPropertyValuesAsync(changedEntry.NewEntry);

                    break;

                case EntryState.Deleted:
                    await _dynamicPropertyService.DeleteDynamicPropertyValuesAsync(changedEntry.NewEntry);

                    break;
                }
            }
        }
 protected virtual async Task SaveDynamicPropertyValuesAsync(Store entry)
 {
     var taskSaveDynamicPropertyValues = _dynamicPropertyService.SaveDynamicPropertyValuesAsync(entry);
     var taskSaveEntitySettingsValues  = _settingManager.DeepSaveSettingsAsync(entry);
     await Task.WhenAll(taskSaveDynamicPropertyValues, taskSaveEntitySettingsValues);
 }
        public void SaveDynamicPropertyValuesInBackground(DynamicContentItem newEntry)
        {
            var dynamicProperties = (IHasDynamicProperties)newEntry;

            _dynamicPropertyService.SaveDynamicPropertyValuesAsync(dynamicProperties).GetAwaiter().GetResult();
        }