private static async Task <IDictionary <long, MediaLocation> > GetMediaLocationDictionary(EcommerceContext ecommerceContext, IEnumerable <long> productIds, IEnumerable <ProductCatalog> catalogs) { long channelId = await Utilities.GetChannelId(ecommerceContext); var distinctProductIds = productIds.Distinct(); ManagerFactory managerFactory = Utilities.GetManagerFactory(ecommerceContext); IProductManager productManager = managerFactory.GetManager <IProductManager>(); IDictionary <long, MediaLocation> mediaLocationDictionary = new Dictionary <long, MediaLocation>(); QueryResultSettings queryResultSettings = new QueryResultSettings() { Paging = new PagingInfo() { Skip = 0, Top = 1 } }; ProductCatalog firstCatalog = catalogs.FirstOrDefault(); long catalogId = (firstCatalog == null) ? 0 : firstCatalog.RecordId; foreach (var productId in distinctProductIds) { PagedResult <MediaLocation> mediaLocations = await productManager.GetMediaLocations(productId, channelId, catalogId, queryResultSettings : queryResultSettings); if (mediaLocations.Any()) { mediaLocationDictionary.Add(productId, mediaLocations.First()); } } return(mediaLocationDictionary); }
/// <summary> /// Get the category from the product identifier. /// </summary> /// <param name="id">Id of particular property.</param> /// <param name="categories">List of all categories.</param> /// <returns>Category belonging to that product.</returns> private Category GetCategoryById(long?id, PagedResult <Category> categories) { return(categories.First(c => c.RecordId == id)); }