public virtual Store Create(Store store) { var pkMap = new PrimaryKeyResolvingMap(); ValidateStoreProperties(store); var dbStore = AbstractTypeFactory <StoreEntity> .TryCreateInstance(); dbStore = dbStore.FromModel(store, pkMap); using (var repository = _repositoryFactory()) { repository.Add(dbStore); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } //Need add seo separately _commerceService.UpsertSeoForObjects(new[] { store }); //Deep save properties _dynamicPropertyService.SaveDynamicPropertyValues(store); //Deep save settings _settingManager.SaveEntitySettingsValues(store); var retVal = GetById(store.Id); return(retVal); }
public void Create(coreModel.CatalogProduct[] items) { var pkMap = new PrimaryKeyResolvingMap(); using (var repository = _catalogRepositoryFactory()) { foreach (var item in items) { var dbItem = item.ToDataModel(pkMap); if (item.Variations != null) { foreach (var variation in item.Variations) { variation.MainProductId = dbItem.Id; variation.CatalogId = dbItem.CatalogId; var dbVariation = variation.ToDataModel(pkMap); dbItem.Childrens.Add(dbVariation); } } repository.Add(dbItem); } CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } //Update SEO var itemsWithVariations = items.Concat(items.Where(x => x.Variations != null).SelectMany(x => x.Variations)).ToArray(); _commerceService.UpsertSeoForObjects(itemsWithVariations); }
public coreModel.Store Create(coreModel.Store store) { var dbStore = store.ToDataModel(); using (var repository = _repositoryFactory()) { repository.Add(dbStore); CommitChanges(repository); store.Id = dbStore.Id; } //Need add seo separately _commerceService.UpsertSeoForObjects(new[] { store }); //Deep save properties _dynamicPropertyService.SaveDynamicPropertyValues(store); //Deep save settings _settingManager.SaveEntitySettingsValues(store); //Invalidate module cache region _cacheManager.ClearRegion("StoreModuleRegion"); var retVal = GetById(store.Id); return(retVal); }
public coreModel.Category Create(coreModel.Category category) { if (category == null) { throw new ArgumentNullException("category"); } var pkMap = new PrimaryKeyResolvingMap(); var dbCategory = category.ToDataModel(pkMap); using (var repository = _catalogRepositoryFactory()) { repository.Add(dbCategory); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } //Need add seo separately _commerceService.UpsertSeoForObjects(new[] { category }); return(GetById(dbCategory.Id, Domain.Catalog.Model.CategoryResponseGroup.Info)); }
public void Create(coreModel.Category[] categories) { if (categories == null) { throw new ArgumentNullException("categories"); } var pkMap = new PrimaryKeyResolvingMap(); var dbCategories = categories.Select(x => x.ToDataModel(pkMap)); using (var repository = _catalogRepositoryFactory()) { foreach (var dbCategory in dbCategories) { repository.Add(dbCategory); } CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } //Need add seo separately _commerceService.UpsertSeoForObjects(categories); }
protected virtual void SaveChanges(CatalogProduct[] products, bool disableValidation = false) { var pkMap = new PrimaryKeyResolvingMap(); var changedEntries = new List <GenericChangedEntry <CatalogProduct> >(); ValidateProducts(products); using (var repository = _repositoryFactory()) using (var changeTracker = GetChangeTracker(repository)) { var dbExistProducts = repository.GetItemByIds(products.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray(), ItemResponseGroup.ItemLarge); foreach (var product in products) { var modifiedEntity = AbstractTypeFactory <ItemEntity> .TryCreateInstance().FromModel(product, pkMap); var originalEntity = dbExistProducts.FirstOrDefault(x => x.Id == product.Id); if (originalEntity != null) { changeTracker.Attach(originalEntity); changedEntries.Add(new GenericChangedEntry <CatalogProduct>(product, originalEntity.ToModel(AbstractTypeFactory <CatalogProduct> .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 <CatalogProduct>(product, EntryState.Added)); } } _eventPublisher.Publish(new ProductChangingEvent(changedEntries)); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); _eventPublisher.Publish(new ProductChangedEvent(changedEntries)); } //Update SEO var productsWithVariations = products.Concat(products.Where(x => x.Variations != null).SelectMany(x => x.Variations)).OfType <ISeoSupport>().ToArray(); _commerceService.UpsertSeoForObjects(productsWithVariations); }
protected virtual void SaveChanges(Category[] categories) { var pkMap = new PrimaryKeyResolvingMap(); var changedEntries = new List <GenericChangedEntry <Category> >(); ValidateCategoryProperties(categories); using (var repository = _repositoryFactory()) using (var changeTracker = GetChangeTracker(repository)) { var dbExistCategories = repository.GetCategoriesByIds(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) { changeTracker.Attach(originalEntity); 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)); } } _eventPublisher.Publish(new CategoryChangingEvent(changedEntries)); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); //Reset cached categories and catalogs ResetCache(); _eventPublisher.Publish(new CategoryChangedEvent(changedEntries)); } //Need add seo separately _commerceService.UpsertSeoForObjects(categories.OfType <ISeoSupport>().ToArray()); }
protected virtual void SaveChanges(Category[] categories) { var pkMap = new PrimaryKeyResolvingMap(); ValidateCategoryProperties(categories); using (var repository = _repositoryFactory()) using (var changeTracker = GetChangeTracker(repository)) { //Optimize performance and CPU usage repository.DisableChangesTracking(); var dbExistCategories = repository.GetCategoriesByIds(categories.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray(), Domain.Catalog.Model.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) { changeTracker.Attach(originalEntity); 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); } } ((System.Data.Entity.DbContext)repository).ChangeTracker.DetectChanges(); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); //Reset cached categories and catalogs ResetCache(); } //Need add seo separately _commerceService.UpsertSeoForObjects(categories); }
public void UpsertSeoForObjects(ISeoSupport[] seoSupportObjects) { _commerceService.UpsertSeoForObjects(seoSupportObjects); }