Example #1
0
        public async Task <IEnumerable <Promotion> > GetAll()
        {
            IEnumerable <Promotion> promotions;

            using (var context = _contextFactory.CreateInstance())
            {
                promotions = await context.Promotions.ToListAsync();

                if (!promotions.Any())
                {
                    throw new ApplicationException("No promotions found");
                }
            }

            return(promotions);
        }
Example #2
0
        public async Task <IEnumerable <Product> > GetAll()
        {
            var cacheKey = $"{nameof(Product)}:{nameof(GetAll)}";
            var models   = await _cacheAccessor.GetAsync <IEnumerable <Product> >(cacheKey);

            if (models == null)
            {
                using (var context = _contextFactory.CreateInstance())
                {
                    models = await context.Products
                             .ToListAsync();
                }

                await _cacheAccessor.SetAsync(models, cacheKey, TimeSpan.FromSeconds(CACHE_SECONDS));
            }

            return(models);
        }