/// <returns>A task that represents the asynchronous operation</returns> protected virtual async Task SaveStoreMappingsAsync(NewsItem newsItem, NewsItemModel model) { newsItem.LimitedToStores = model.SelectedStoreIds.Any(); await _newsService.UpdateNewsAsync(newsItem); var existingStoreMappings = await _storeMappingService.GetStoreMappingsAsync(newsItem); var allStores = await _storeService.GetAllStoresAsync(); foreach (var store in allStores) { if (model.SelectedStoreIds.Contains(store.Id)) { //new store if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0) { await _storeMappingService.InsertStoreMappingAsync(newsItem, store.Id); } } else { //remove store var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) { await _storeMappingService.DeleteStoreMappingAsync(storeMappingToDelete); } } } }
protected virtual async Task SaveStoreMappingsAsync(Topic topic, TopicModel model) { topic.LimitedToStores = model.SelectedStoreIds.Any(); await _topicService.UpdateTopicAsync(topic); var existingStoreMappings = await _storeMappingService.GetStoreMappingsAsync(topic); var allStores = await _storeService.GetAllStoresAsync(); foreach (var store in allStores) { if (model.SelectedStoreIds.Contains(store.Id)) { //new store if (!existingStoreMappings.Any(sm => sm.StoreId == store.Id)) { await _storeMappingService.InsertStoreMappingAsync(topic, store.Id); } } else { //remove store var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) { await _storeMappingService.DeleteStoreMappingAsync(storeMappingToDelete); } } } }
protected async Task UpdateStoreMappingsAsync <TEntity>(TEntity entity, List <int> passedStoreIds) where TEntity : BaseEntity, IStoreMappingSupported { if (passedStoreIds == null) { return; } entity.LimitedToStores = passedStoreIds.Any(); var existingStoreMappings = await StoreMappingService.GetStoreMappingsAsync(entity); var allStores = await StoreService.GetAllStoresAsync(); foreach (var store in allStores) { if (passedStoreIds.Contains(store.Id)) { //new store if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0) { await StoreMappingService.InsertStoreMappingAsync(entity, store.Id); } } else { //remove store var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) { await StoreMappingService.DeleteStoreMappingAsync(storeMappingToDelete); } } } }
/// <summary> /// Get the store that the given product is on, /// limited by the export settings. /// If it is multiple, the one with the smallest ID is given. /// If it is not on any after limiting, then NULL is returned. /// </summary> /// <returns> /// NULL means none found given settings. /// Otherwise, the store that the given product is on. /// </returns> private async Task <Store> GetProductStoreAsync(Product product) { // Find all store mappings to this product. // Limit by the given export settings. // Use the URL of (only) the first store that meets all the criteria. var storeList = await _storeMappingService.GetStoreMappingsAsync(product); foreach (var storeMapping in storeList) { var store = await _storeService.GetStoreByIdAsync(storeMapping.StoreId); if (_settings.ExportAbcWarehouse && (store.Name.Contains("ABC"))) { return(store); } if (_settings.ExportHawthorne && (store.Name.Contains("Hawthorne"))) { return(store); } } return(null); }
private async Task SaveStoreMappingsAsync <TEntity, TModel>(TEntity entity, TModel model) where TEntity : BaseEntity, IStoreMappingSupported where TModel : BaseNopEntityModel, IStoreMappingSupportedModel { var existingStoreMappings = await _storeMappingService.GetStoreMappingsAsync(entity); var allStores = await _storeService.GetAllStoresAsync(); foreach (var store in allStores) { if (model.SelectedStoreIds.Contains(store.Id)) { //new store if (!existingStoreMappings.Any(sm => sm.StoreId == store.Id)) { await _storeMappingService.InsertStoreMappingAsync(entity, store.Id); } } else { //remove store var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) { await _storeMappingService.DeleteStoreMappingAsync(storeMappingToDelete); } } } }
/// <returns>A task that represents the asynchronous operation</returns> protected virtual async Task SaveStoreMappingsAsync(Poll poll, PollModel model) { poll.LimitedToStores = model.SelectedStoreIds.Any(); await _pollService.UpdatePollAsync(poll); //manage store mappings var existingStoreMappings = await _storeMappingService.GetStoreMappingsAsync(poll); foreach (var store in await _storeService.GetAllStoresAsync()) { var existingStoreMapping = existingStoreMappings.FirstOrDefault(storeMapping => storeMapping.StoreId == store.Id); //new store mapping if (model.SelectedStoreIds.Contains(store.Id)) { if (existingStoreMapping == null) { await _storeMappingService.InsertStoreMappingAsync(poll, store.Id); } } //or remove existing one else if (existingStoreMapping != null) { await _storeMappingService.DeleteStoreMappingAsync(existingStoreMapping); } } }
private async System.Threading.Tasks.Task ProcessItemNoAsync(string itemNo) { var pad = await _productAbcDescriptionService.GetProductAbcDescriptionByAbcItemNumberAsync( itemNo ); if (pad == null) { return; } var product = await _productService.GetProductByIdAsync(pad.Product_Id); await UnmapFromStoreAsync(product, pad); if (!(await _storeMappingService.GetStoreMappingsAsync(product)).Any()) { await _productService.DeleteProductAsync(product); } }
public async Task <ProductDto> PrepareProductDTOAsync(Product product) { var productDto = product.ToDto(); var productPictures = await _productService.GetProductPicturesByProductIdAsync(product.Id); await PrepareProductImagesAsync(productPictures, productDto); productDto.SeName = await _urlRecordService.GetSeNameAsync(product); productDto.DiscountIds = (await _discountService.GetAppliedDiscountsAsync(product)).Select(discount => discount.Id).ToList(); productDto.ManufacturerIds = (await _manufacturerService.GetProductManufacturersByProductIdAsync(product.Id)).Select(pm => pm.Id).ToList(); productDto.RoleIds = (await _aclService.GetAclRecordsAsync(product)).Select(acl => acl.CustomerRoleId).ToList(); productDto.StoreIds = (await _storeMappingService.GetStoreMappingsAsync(product)).Select(mapping => mapping.StoreId).ToList(); productDto.Tags = (await _productTagService.GetAllProductTagsByProductIdAsync(product.Id)).Select(tag => tag.Name).ToList(); productDto.AssociatedProductIds = (await _productService.GetAssociatedProductsAsync(product.Id, showHidden: true)) .Select(associatedProduct => associatedProduct.Id) .ToList(); var allLanguages = await _languageService.GetAllLanguagesAsync(); productDto.LocalizedNames = new List <LocalizedNameDto>(); foreach (var language in allLanguages) { var localizedNameDto = new LocalizedNameDto { LanguageId = language.Id, LocalizedName = await _localizationService.GetLocalizedAsync(product, x => x.Name, language.Id) }; productDto.LocalizedNames.Add(localizedNameDto); } return(productDto); }