Exemple #1
0
        protected override void PersistNewItem(IProduct entity)
        {
            Mandate.ParameterCondition(SkuExists(entity.Sku) == false, "Skus must be unique.");

            ((Product)entity).AddingEntity();
            ((ProductVariant)((Product)entity).MasterVariant).VersionKey = Guid.NewGuid();

            var factory = new ProductFactory();
            var dto     = factory.BuildDto(entity);

            // save the product
            Database.Insert(dto);
            entity.Key = dto.Key;

            // setup and save the master (singular) variant
            dto.ProductVariantDto.ProductKey = dto.Key;
            Database.Insert(dto.ProductVariantDto);
            Database.Insert(dto.ProductVariantDto.ProductVariantIndexDto);

            ((Product)entity).MasterVariant.ProductKey = dto.ProductVariantDto.ProductKey;
            ((Product)entity).MasterVariant.Key        = dto.ProductVariantDto.Key;
            ((ProductVariant)((Product)entity).MasterVariant).ExamineId = dto.ProductVariantDto.ProductVariantIndexDto.Id;

            // save the product options
            SaveProductOptions(entity);

            // synchronize the inventory
            ((ProductVariantRepository)_productVariantRepository).SaveCatalogInventory(((Product)entity).MasterVariant);

            entity.ResetDirtyProperties();
        }
Exemple #2
0
        protected override void PersistUpdatedItem(IProduct entity)
        {
            ((Product)entity).UpdatingEntity();

            var factory = new ProductFactory();
            var dto     = factory.BuildDto(entity);

            Database.Update(dto);
            Database.Update(dto.ProductVariantDto);

            SaveProductOptions(entity);

            // synchronize the inventory
            ((ProductVariantRepository)_productVariantRepository).SaveCatalogInventory(((Product)entity).MasterVariant);

            entity.ResetDirtyProperties();
        }