示例#1
0
        public async Task <IEnumerable <ItemCategory> > GetItemCategoriesFromIdsAsync(IEnumerable <int> itemCategoryIds)
        {
            if (ItemCategoriesMap == null || !ItemCategoriesMap.Any())
            {
                await SetUpItemCategoriesListAsync();
            }

            return(ItemCategoriesMap.Where(m => itemCategoryIds.Contains(m.Key)).Select(m => m.Value).ToList());
        }
示例#2
0
        public async Task <IEnumerable <int> > GetItemCategoryIdsAsync()
        {
            if (ItemCategoriesMap == null || !ItemCategoriesMap.Any())
            {
                await SetUpItemCategoriesListAsync();
            }

            return(GetItemCategoryIds());
        }
示例#3
0
        public async Task SetUpItemCategoriesListAsync()
        {
            await _itemCategoryMapSetUpSemaphore.WaitAsync();

            try
            {
                using var factory = _dbContextHelper.GetFactory();
                var dbContext = factory.GetDbContext();

                var storeCategories = await dbContext.ItemCategories.ToListAsync();

                foreach (var categoryId in ItemCategoriesMap.Keys)
                {
                    if (!storeCategories.Any(c => c.Id == categoryId))
                    {
                        ItemCategoriesMap.TryRemove(categoryId, out var removedItem);
                    }
                }

                foreach (var category in storeCategories)
                {
                    if (ItemCategoriesMap.ContainsKey(category.Id))
                    {
                        ItemCategoriesMap[category.Id] = category;
                    }
                    else
                    {
                        ItemCategoriesMap.TryAdd(category.Id, category);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error setting up Item Categories Map: {ex}");
            }
            finally
            {
                _itemCategoryMapSetUpSemaphore.Release();
            }
        }