Beispiel #1
0
        public async Task <Domain.Entities.Manufacturer.Manufacturer> GetAsync(Guid manufacturerId, bool @readonly)
        {
            if (@readonly)
            {
                var cached =
                    _cachingRepository.Get <Domain.Entities.Manufacturer.Manufacturer>(manufacturerId.ToString());

                if (cached != null)
                {
                    return(cached);
                }
            }

            var query = _context.Manufacturers
                        .Include(x => x.Pictures)
                        .ThenInclude(x => x.Picture)
                        .ThenInclude(x => x.MimeType)
                        .AsQueryable();

            if (@readonly)
            {
                query = query.AsNoTracking();
            }

            var manufacturer = await query.FirstOrDefaultAsync(x => x.Id.Equals(manufacturerId));

            if (manufacturer != null && @readonly)
            {
                _cachingRepository.Cache(manufacturerId.ToString(), query);
            }

            return(manufacturer);
        }
        public async Task <bool> AnyAsync(Guid id)
        {
            var cached = _cachingRepository.Get <Domain.Entities.Product.Category>($"CategoryAsNoTracking_{id}");

            if (cached != null)
            {
                return(true);
            }

            var category = await _context.Categories
                           .AsNoTracking()
                           .AnyAsync(x => x.Id.Equals(id));

            if (category)
            {
                _cachingRepository.Cache(id.ToString(), true);
            }

            return(category);
        }
        public async Task <Domain.Entities.Product.Product> GetAsync(Guid productId, bool @readonly,
                                                                     CancellationToken cancellationToken)
        {
            if (@readonly)
            {
                var cached = _cachingRepository.Get <Domain.Entities.Product.Product>(productId.ToString());

                if (cached != null)
                {
                    return(cached);
                }
            }

            var query = _context
                        .Products
                        .Include(x => x.Category)
                        .Include(x => x.Pictures)
                        .ThenInclude(x => x.Picture)
                        .ThenInclude(x => x.MimeType)
                        .Include(x => x.ProductType)
                        .Include(x => x.Dimensions)
                        .AsQueryable();

            if (@readonly)
            {
                query = query.AsNoTracking();
            }

            var product =
                await query.FirstOrDefaultAsync(x => x.Id.Equals(productId), cancellationToken : cancellationToken);

            if (product != null && @readonly)
            {
                _cachingRepository.Cache(productId.ToString(), query);
            }

            return(product);
        }