public coreModel.Store Create(coreModel.Store store) { var dbStore = store.ToDataModel(); coreModel.Store retVal = null; using (var repository = _repositoryFactory()) { repository.Add(dbStore); CommitChanges(repository); } //Need add seo separately if (store.SeoInfos != null) { foreach (var seoInfo in store.SeoInfos) { seoInfo.ObjectId = dbStore.Id; seoInfo.ObjectType = typeof(coreModel.Store).Name; _commerceService.UpsertSeo(seoInfo); } } //Deep save settings SaveObjectSettings(_settingManager, store); retVal = GetById(store.Id); return retVal; }
public coreModel.Store Create(coreModel.Store store) { var dbStore = store.ToDataModel(); using (var repository = _repositoryFactory()) { repository.Add(dbStore); CommitChanges(repository); } //Need add seo separately if (store.SeoInfos != null) { foreach (var seoInfo in store.SeoInfos) { seoInfo.ObjectId = dbStore.Id; seoInfo.ObjectType = typeof(coreModel.Store).Name; _commerceService.UpsertSeo(seoInfo); } } //Deep save properties _dynamicPropertyService.SaveDynamicPropertyValues(store); //Deep save settings _settingManager.SaveEntitySettingsValues(store); //Reset cache var cacheKey = CacheKey.Create("StoreModule", "GetById", store.Id); _cacheManager.Remove(cacheKey); var retVal = GetById(store.Id); return retVal; }
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 webModel.SearchResult SearchStores(coreModel.SearchCriteria criteria) { //Filter resulting stores correspond to current user permissions //first check global permission if (!_securityService.UserHasAnyPermission(User.Identity.Name, null, StorePredefinedPermissions.Read)) { //Get user 'read' permission scopes criteria.StoreIds = _securityService.GetUserPermissions(User.Identity.Name) .Where(x => x.Id.StartsWith(StorePredefinedPermissions.Read)) .SelectMany(x => x.AssignedScopes) .OfType<StoreSelectedScope>() .Select(x => x.Scope) .ToArray(); } var result = _storeService.SearchStores(criteria); var retVal = new webModel.SearchResult { TotalCount = result.TotalCount, Stores = result.Stores.Select(x => x.ToWebModel()).ToArray() }; return retVal; }
private IEnumerable<CatalogItem> InnerGetProductsByIds(storeModel.Store store, String[] ids, ItemResponseGroup responseGroup) { var retVal = new List<CatalogItem>(); var products = _itemService.GetByIds(ids, responseGroup);//.Where(p=>p.CatalogId == store.Catalog); foreach (var product in products) { coreModel.Property[] properties = null; if ((responseGroup & ItemResponseGroup.ItemProperties) == ItemResponseGroup.ItemProperties) { properties = GetAllProductProperies(product); } if (product != null) { var webModelProduct = product.ToWebModel(_blobUrlResolver, properties); if (product.CategoryId != null) { var category = _categoryService.GetById(product.CategoryId); webModelProduct.Outline = string.Join("/", category.Parents.Select(x => x.Id)) + "/" + category.Id; } retVal.Add(webModelProduct); } } if ((responseGroup & ItemResponseGroup.Inventory) == ItemResponseGroup.Inventory) { this.PopulateInventory(store.FulfillmentCenter, retVal); } return retVal; }
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); _dynamicPropertyService.SaveDynamicPropertyValues(store); //Deep save settings _settingManager.SaveEntitySettingsValues(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)); } //Reset cache var cacheKey = CacheKey.Create("StoreModule", "GetById", store.Id); _cacheManager.Remove(cacheKey); } 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); _dynamicPropertyService.SaveDynamicPropertyValues(store); //Deep save settings _settingManager.SaveEntitySettingsValues(store); //Patch SeoInfo separately _commerceService.UpsertSeoForObjects(stores); } 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 string[] { store.Id })); seoInfos.ObserveCollection(x => _commerceService.UpsertSeo(x), x => _commerceService.DeleteSeo(new string[] { x.Id })); store.SeoInfos.Patch(seoInfos, (source, target) => _commerceService.UpsertSeo(source)); } } CommitChanges(repository); } }
public coreModel.SearchResult SearchStores(coreModel.SearchCriteria criteria) { var retVal = new coreModel.SearchResult(); using (var repository = _repositoryFactory()) { var query = repository.Stores; if(!string.IsNullOrEmpty(criteria.Keyword)) { query = query.Where(x => x.Name.Contains(criteria.Keyword) || x.Id.Contains(criteria.Keyword)); } if(!criteria.StoreIds.IsNullOrEmpty()) { query = query.Where(x => criteria.StoreIds.Contains(x.Id)); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "Name" } }; } query = query.OrderBySortInfos(sortInfos); retVal.TotalCount = query.Count(); var storeIds = query.Skip(criteria.Skip) .Take(criteria.Take) .Select(x => x.Id) .ToArray(); retVal.Stores = GetByIds(storeIds).AsQueryable().OrderBySortInfos(sortInfos).ToList(); } return retVal; }
public void Update(coreModel.Store[] stores) { using (var repository = _repositoryFactory()) using (var changeTracker = base.GetChangeTracker(repository)) { var dbStores = repository.GetStoresByIds(stores.Select(x => x.Id).ToArray()); foreach (var store in stores) { var sourceEntity = store.ToDataModel(); var targetEntity = dbStores.First(x=>x.Id == store.Id); if (targetEntity == null) { throw new NullReferenceException("targetEntity"); } changeTracker.Attach(targetEntity); sourceEntity.Patch(targetEntity); _dynamicPropertyService.SaveDynamicPropertyValues(store); //Deep save settings _settingManager.SaveEntitySettingsValues(store); //Patch SeoInfo separately _commerceService.UpsertSeoForObjects(stores); } CommitChanges(repository); //Invalidate module cache region _cacheManager.ClearRegion("StoreModuleRegion"); } }