public void Update(coreModel.Category[] categories) { using (var repository = _catalogRepositoryFactory()) using (var changeTracker = base.GetChangeTracker(repository)) { foreach (var category in categories) { var dbCategory = repository.GetCategoryById(category.Id) as dataModel.Category; if (dbCategory == null) { throw new NullReferenceException("dbCategory"); } //Patch SeoInfo separately if (category.SeoInfos != null) { foreach (var seoInfo in category.SeoInfos) { seoInfo.ObjectId = category.Id; seoInfo.ObjectType = typeof(coreModel.Category).Name; } var seoInfos = new ObservableCollection <SeoInfo>(_commerceService.GetObjectsSeo(new string[] { category.Id })); seoInfos.ObserveCollection(x => _commerceService.UpsertSeo(x), x => _commerceService.DeleteSeo(new string[] { x.Id })); category.SeoInfos.Patch(seoInfos, (source, target) => _commerceService.UpsertSeo(source)); } var dbCategoryChanged = category.ToDataModel(); changeTracker.Attach(dbCategory); category.Patch(dbCategory); } CommitChanges(repository); } }
public void Delete(string[] catalogIds) { using (var repository = _catalogRepositoryFactory()) { var seoInfos = _commerceService.GetObjectsSeo(catalogIds); _commerceService.DeleteSeo(seoInfos.Select(x => x.Id).ToArray()); repository.RemoveCatalogs(catalogIds); CommitChanges(repository); } }
public void Update(coreModel.CatalogProduct[] items) { var now = DateTime.UtcNow; using (var repository = _catalogRepositoryFactory()) using (var changeTracker = base.GetChangeTracker(repository)) { var dbItems = repository.GetItemByIds(items.Select(x => x.Id).ToArray(), coreModel.ItemResponseGroup.ItemLarge); foreach (var dbItem in dbItems) { var item = items.FirstOrDefault(x => x.Id == dbItem.Id); if (item != null) { //Need skip inherited properties without overridden value if (dbItem.ParentId != null && item.PropertyValues != null) { var dbParentItem = repository.GetItemByIds(new[] { dbItem.ParentId }, coreModel.ItemResponseGroup.ItemProperties).First(); item.MainProduct = dbParentItem.ToCoreModel(new coreModel.Catalog { Id = dbItem.CatalogId }, new coreModel.Category { Id = dbItem.CategoryId }, null); } changeTracker.Attach(dbItem); item.Patch(dbItem); } //Patch seoInfo if (item.SeoInfos != null) { foreach (var seoInfo in item.SeoInfos) { seoInfo.ObjectId = item.Id; seoInfo.ObjectType = typeof(coreModel.CatalogProduct).Name; } var seoInfos = new ObservableCollection <SeoInfo>(_commerceService.GetObjectsSeo(new[] { item.Id })); seoInfos.ObserveCollection(x => _commerceService.UpsertSeo(x), x => _commerceService.DeleteSeo(new[] { x.Id })); item.SeoInfos.Patch(seoInfos, (source, target) => _commerceService.UpsertSeo(source)); } } CommitChanges(repository); } }
public void Update(coreModel.Store[] stores) { using (var repository = _repositoryFactory()) using (var changeTracker = base.GetChangeTracker(repository)) { foreach (var store in stores) { var sourceEntity = store.ToDataModel(); var targetEntity = repository.GetStoreById(store.Id); if (targetEntity == null) { throw new NullReferenceException("targetEntity"); } changeTracker.Attach(targetEntity); sourceEntity.Patch(targetEntity); SaveObjectSettings(_settingManager, store); //Patch SeoInfo separately if (store.SeoInfos != null) { foreach (var seoInfo in store.SeoInfos) { seoInfo.ObjectId = store.Id; seoInfo.ObjectType = typeof(coreModel.Store).Name; } var seoInfos = new ObservableCollection <SeoInfo>(_commerceService.GetObjectsSeo(new[] { store.Id })); seoInfos.ObserveCollection(x => _commerceService.UpsertSeo(x), x => _commerceService.DeleteSeo(new[] { x.Id })); store.SeoInfos.Patch(seoInfos, (source, target) => _commerceService.UpsertSeo(source)); } } CommitChanges(repository); } }