Beispiel #1
0
        public IList <ProductSummary> GetAll()
        {
            var products = _productStorage.GetAll();

            //Good place to use automapper
            return(products.Select(x => new ProductSummary {
                Id = x.Id, Name = x.Name, Price = x.Price, Image = x.Image
            }).ToList());
        }
Beispiel #2
0
        private async void WarmUpService()
        {
            var startItems = _productStorage.GetAll();

            if (startItems.Count == 0)
            {
                await GenerateItems();
            }
        }
Beispiel #3
0
        public IEnumerable <Product> GetAll()
        {
            // See if all was previously cached as a list
            if (_cache.TryGetValue(AllCacheKey, out IList <Product> all) == false)
            {
                // Update all the individual items in the cache, because we do not know if we have seen all elements
                all = _inner
                      .GetAll()
                      .ToList();
                foreach (Product product in all)
                {
                    _cache.Set(product.Id.ToCacheKey(), product);
                }

                // Create a separate cache item for the full collection as a list
                // (for easy returning as well as re-updating when Add() is later invoked again)
                _cache.Set(AllCacheKey, all);
            }

            // Necessary to copy Product instances to a new array to avoid exposing cached
            // List <Product>-object to clients (as the list itself is *not* immutable)
            return(all.ToArray());
        }
 public async Task <IEnumerable <ProductOutcomeDTO> > GetAll() => _mapper.Map <IEnumerable <ProductOutcomeDTO> >(await _productStorage.GetAll());
Beispiel #5
0
 public IEnumerable <Product> GetAll() => _inner.GetAll();