Example #1
0
        public void CopyToIndexOutOfRangeLow()
        {
            var entityCollection = new EntityCollection <EntityCollectionModel>();
            var array            = new EntityCollectionModel[4];

            entityCollection.CopyTo(array, -1);
        }
        /// <summary>
        /// Associate Commerce Catgories to given Catalog and Parent Categories
        /// </summary>
        /// <param name="entityModel"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private async Task AssociateCategoriesToParent(EntityCollectionModel entityModel, CommercePipelineExecutionContext context)
        {
            CommerceList <Catalog>  catalogs   = _findEntitiesInListCommand.Process <Catalog>(context.CommerceContext, CommerceEntity.ListName <Catalog>(), 0, int.MaxValue).Result;
            CommerceList <Category> categories = _findEntitiesInListCommand.Process <Category>(context.CommerceContext, CommerceEntity.ListName <Category>(), 0, int.MaxValue).Result;

            foreach (var entity in entityModel.Entities)
            {
                var category = entity as Category;
                if (!string.IsNullOrEmpty(category.ParentCatalogList) || !string.IsNullOrEmpty(category.ParentCategoryList))
                {
                    var parentCatalog = catalogs.Items.FirstOrDefault(i => i.SitecoreId.Equals(category.ParentCatalogList));
                    if (parentCatalog != null)
                    {
                        if (string.IsNullOrEmpty(category.ParentCategoryList))
                        {
                            await _associateCategoryToParentCommand.Process(context.CommerceContext, parentCatalog.Id, parentCatalog.Id, category.Id);
                        }
                        else
                        {
                            foreach (string categorySitecoreId in category.ParentCategoryList.Split('|'))
                            {
                                var parentCategory = categories.Items.FirstOrDefault(i => i.SitecoreId.Equals(categorySitecoreId));
                                if (parentCategory != null)
                                {
                                    await _associateCategoryToParentCommand.Process(context.CommerceContext, parentCatalog.Id, parentCategory.Id, category.Id);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        public EntityCollectionModel GetCollectionEntityImages()
        {
            EntityCollectionModel entities = new EntityCollectionModel();

            entities.OurMemoriesImages = GetImagesBySectionID(1);
            entities.BridesmaidImages  = GetImagesBySectionID(4);
            entities.GroomsmenImages   = GetImagesBySectionID(5);
            entities.MainSliderImages  = GetImagesBySectionID(6);

            return(entities);
        }
Example #4
0
        public void AddNewEntry()
        {
            var entityCollection = new EntityCollection <EntityCollectionModel>();
            var entity           = new EntityCollectionModel
            {
                Title = "DbEntityCollectionTests.AddNewEntry"
            };

            entityCollection.Update(entity, EntityEntryState.Added);

            Assert.IsTrue(entityCollection.GetEntries().All(e => e.Entity == entity && e.State == EntityEntryState.Added));
        }
Example #5
0
        public void ContainsExactEntity()
        {
            var entityCollection = new EntityCollection <EntityCollectionModel>();
            var entity           = new EntityCollectionModel
            {
                Id = "ABC"
            };

            entityCollection.Add(entity);

            Assert.IsTrue(entityCollection.Contains(entity));
        }
Example #6
0
        public void UpdateExistingEntryInstanceMatch()
        {
            var entityCollection = new EntityCollection <EntityCollectionModel>();
            var entity           = new EntityCollectionModel
            {
                Title = "DbEntityCollectionTests.UpdateExistingEntryWithoutId"
            };

            entityCollection.Update(entity, EntityEntryState.Added);
            Assert.IsTrue(entityCollection.GetEntries().All(e => e.Entity == entity && e.State == EntityEntryState.Added));

            entityCollection.Update(entity, EntityEntryState.NoChanges);
            Assert.IsTrue(entityCollection.GetEntries().All(e => e.Entity == entity && e.State == EntityEntryState.NoChanges));
        }
Example #7
0
        public void ClearTracker()
        {
            var entityCollection = new EntityCollection <EntityCollectionModel>();
            var entity           = new EntityCollectionModel
            {
                Title = "DbEntityCollectionTests.ClearTracker"
            };

            entityCollection.Update(entity, EntityEntryState.NoChanges);

            entityCollection.Clear();

            Assert.IsFalse(entityCollection.GetEntries().Any());
        }
        /// <summary>
        /// Save Commmerce Entities collection into Commerce DB
        /// </summary>
        /// <param name="entityModel"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task ImportCommerceEntities(EntityCollectionModel entityModel, CommercePipelineExecutionContext context)
        {
            try
            {
                foreach (var commerceEntity in entityModel.Entities)
                {
                    var entity         = Cast(commerceEntity, entityModel.EntityType);
                    var existingEntity = await _findEntityCommand.Process(context.CommerceContext, entity.GetType(), entity.Id);

                    if (existingEntity != null)
                    {
                        // Try to increase version count instead of delete
                        DeleteEntityArgument result = await _deleteEntityCommand.Process(context.CommerceContext, existingEntity.Id);

                        if (!result.Success)
                        {
                            Log.Error($"{this.GetType().Name}: Deletion of {existingEntity.Id} failed - new Entity was not imported");
                        }
                        else
                        {
                            entity.Version = 0;
                        }
                    }

                    //entity.EntityVersion = 1;
                    //entity.Version = 0;
                    entity.IsPersisted = false;
                    context.CommerceContext.AddUniqueEntityByType(entity);


                    var persistResult = await this._persistEntityCommand.Process(context.CommerceContext, entity);
                }

                if (entityModel.EntityType == typeof(Category))
                {
                    await AssociateCategoriesToParent(entityModel, context);
                }

                if (entityModel.EntityType == typeof(SellableItem))
                {
                    await AssociateSellableItemsToParent(entityModel, context);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #9
0
        public void CopyToIndexOutOfRangeHigh()
        {
            var entityCollection = new EntityCollection <EntityCollectionModel>()
            {
                new EntityCollectionModel {
                },
                new EntityCollectionModel {
                },
                new EntityCollectionModel {
                },
                new EntityCollectionModel {
                }
            };

            var array = new EntityCollectionModel[2];

            entityCollection.CopyTo(array, 1);
        }
Example #10
0
        public void ContainsEntityById()
        {
            var entityCollection = new EntityCollection <EntityCollectionModel>();
            var entity           = new EntityCollectionModel
            {
                Id    = "ABC",
                Title = "1"
            };

            entityCollection.Add(entity);

            var idMatchingEntity = new EntityCollectionModel
            {
                Id = "ABC"
            };

            Assert.IsTrue(entityCollection.Contains(idMatchingEntity));
        }
Example #11
0
        public void UpdateExistingEntryIdMatch()
        {
            var entityCollection = new EntityCollection <EntityCollectionModel>();
            var entity           = new EntityCollectionModel
            {
                Id    = "123",
                Title = "DbEntityCollectionTests.UpdateExistingEntryWithId-1"
            };

            entityCollection.Update(entity, EntityEntryState.Added);
            Assert.IsTrue(entityCollection.GetEntries().All(e => e.Entity == entity && e.State == EntityEntryState.Added));

            var updatedEntity = new EntityCollectionModel
            {
                Id    = "123",
                Title = "DbEntityCollectionTests.UpdateExistingEntryWithId-2"
            };

            entityCollection.Update(updatedEntity, EntityEntryState.Updated);
            Assert.IsFalse(entityCollection.GetEntries().Any(e => e.Entity == entity));
            Assert.IsTrue(entityCollection.GetEntries()
                          .Any(e => e.Entity == updatedEntity && e.Entity.Title == "DbEntityCollectionTests.UpdateExistingEntryWithId-2"));
        }
 /// <summary>
 /// c'tor
 /// </summary>s
 public ImportEntitiesArgument(EntityCollectionModel entities)
 {
     this.EntityModel = entities;
 }