Beispiel #1
0
        /// <summary>
        /// Fetches a specific product with corresponding meta-data (e.g. pricing tier, initial tariff, ...)
        /// </summary>
        /// <param name="id">Product ID to search for</param>
        public async Task <ProductDTO> Get(Guid id)
        {
            using (_dbContext)
            {
                ProductEntity product = await _dbContext.Products.FindAsync(id);

                if (product != null)
                {
                    // Load additional data (used this way to have the benefits of Find() by still including external data)
                    await _dbContext.Entry(product).Reference(p => p.InitialTariff).LoadAsync();

                    if (product.InitialTariff != null)
                    {
                        await _dbContext.Entry(product.InitialTariff).Reference(t => t.NextPricingTier).LoadAsync();
                    }

                    return(product.Adapt <ProductDTO>());
                }

                return(null);
            }
        }