public List <ProductItemDto> GetProductsInBasket(RewardsRequest requestData)
 {
     using (var _rewardEntities = new RewardsEntities())
     {
         return(_rewardEntities.Products
                .Join(requestData.Basket,
                      d => d.ProductId,
                      b => b.ProductId,
                      (d, b) => new ProductItemDto
         {
             ProductId = d.ProductId,
             UnitPrice = d.UnitPrice,
             Quantity = b.Quantity,
         }).ToList());
     }
 }
 public List <DiscountedProductDto> GetDiscountedProducts(RewardsRequest requestData)
 {
     using (var _rewardEntities = new RewardsEntities())
     {
         return(_rewardEntities.DiscountPromotionProducts
                .Include(i => i.DiscountPromotion)
                .Include(p => p.Product)
                .Join(requestData.Basket,
                      d => d.ProductId,
                      b => b.ProductId,
                      (d, b) => new { d.ProductId, d.DiscountPromotion, d.Product, b.Quantity })
                .Where(d => d.DiscountPromotion.StartDate <= requestData.TransactionDate &&
                       d.DiscountPromotion.EndDate >= requestData.TransactionDate).ToList()
                .GroupBy(s => s.ProductId).
                Select(g => new DiscountedProductDto {
             ProductId = g.Key, DiscountPercent = g.Sum(q => q.DiscountPromotion.DiscountPercent)
         }).ToList());
     }
 }
 public List <PointsPromotionDto> GetProductPoints(RewardsRequest requestData)
 {
     using (var _rewardEntities = new RewardsEntities())
     {
         return(_rewardEntities.Products
                .Join(requestData.Basket,
                      d => d.ProductId,
                      b => b.ProductId,
                      (d, b) => new { d.ProductId, d.UnitPrice, d.Category, b.Quantity })
                .Join(_rewardEntities.PointsPromotions,                 //Doing Cartesian Join and matching category in where clause
                      d => "Any",
                      pr => "Any",
                      (d, pr) => new { d.ProductId, d.Category, PromoCategory = pr.Category, pr.PointsPerDollar, pr.StartDate, pr.EndDate })
                .Where(pr => pr.StartDate <= requestData.TransactionDate && pr.EndDate >= requestData.TransactionDate &&
                       (pr.Category == pr.PromoCategory || pr.PromoCategory == "Any"))
                .Select(res => new PointsPromotionDto {
             ProductId = res.ProductId,
             PointsPerDollar = res.PointsPerDollar
         })
                .ToList());
     }
 }