public IDataLookupResult LookupData(IDataLookupContext dataLookupContext) { if (OnLookupData != null) { return(OnLookupData(dataLookupContext)); } return(null); }
static IQueryable <PromotionsData.Order> DateFilterOrders(IDataLookupContext dataLookupContext, IQueryable <PromotionsData.Order> orders) { var retVal = orders; var startDate = CalculateQueryDate(dataLookupContext.StartDateType, dataLookupContext.CustomStartDate, dataLookupContext.PromotionId, dataLookupContext.CustomerId); var endDate = CalculateQueryDate(dataLookupContext.EndDateType, dataLookupContext.CustomEndDate, dataLookupContext.PromotionId, dataLookupContext.CustomerId); if (startDate != DateTime.MinValue && endDate != DateTime.MinValue) { retVal = retVal.Where(o => startDate <= o.OrderDate && o.OrderDate <= endDate); } return(retVal); }
static IQueryable <PromotionsData.PromotionUsage> DateFilterPromotionUsage(IDataLookupContext dataLookupContext, IQueryable <PromotionsData.PromotionUsage> promotionUsages) { var retVal = promotionUsages .Where(pu => pu.DateApplied.HasValue); var startDate = CalculateQueryDate(dataLookupContext.StartDateType, dataLookupContext.CustomStartDate, dataLookupContext.PromotionId, dataLookupContext.CustomerId); var endDate = CalculateQueryDate(dataLookupContext.EndDateType, dataLookupContext.CustomEndDate, dataLookupContext.PromotionId, dataLookupContext.CustomerId); if (startDate != DateTime.MinValue && endDate != DateTime.MinValue) { retVal = retVal.Where(pu => startDate <= pu.DateApplied.Value && pu.DateApplied.Value <= endDate); } return(retVal); }
static IDataLookupResult PromotionController_OnLookupData(IDataLookupContext dataLookupContext) { var lookupResult = new SimpleDataLookupResult(); switch (dataLookupContext.LookupType) { case LookupType.TotalPromotionUses: var promotionUsages = PromotionsData.DataContextProvider .Current .PromotionUsages .Where(pu => pu.Complete); if (dataLookupContext.CustomerId > 0) { promotionUsages = promotionUsages .Where(pu => pu.CustomerId == dataLookupContext.CustomerId); } if (dataLookupContext.PromotionId > 0) { promotionUsages = promotionUsages .Where(pu => pu.PromotionId == dataLookupContext.PromotionId); } promotionUsages = DateFilterPromotionUsage(dataLookupContext, promotionUsages); lookupResult.Int32Result = promotionUsages.Count(); break; case LookupType.TotalOrders: var totalOrders = (IQueryable <PromotionsData.Order>)PromotionsData.DataContextProvider .Current .Orders; if (dataLookupContext.CustomerId > 0) { totalOrders = totalOrders .Where(o => o.CustomerID == dataLookupContext.CustomerId); } totalOrders = DateFilterOrders(dataLookupContext, totalOrders); lookupResult.Int32Result = totalOrders.Count(); break; case LookupType.TotalOrderAmount: var totalOrderAmount = (IQueryable <PromotionsData.Order>)PromotionsData.DataContextProvider.Current.Orders; if (dataLookupContext.CustomerId > 0) { totalOrderAmount = totalOrderAmount .Where(o => o.CustomerID == dataLookupContext.CustomerId); } totalOrderAmount = DateFilterOrders(dataLookupContext, totalOrderAmount); lookupResult.DecimalResult = totalOrderAmount.Any() ? totalOrderAmount.Sum(o => o.OrderTotal) : 0.00M; break; case LookupType.TotalProductOrdered: var totalProducts = (IQueryable <PromotionsData.Orders_ShoppingCart>)PromotionsData.DataContextProvider .Current .Orders_ShoppingCarts .Where(w => !dataLookupContext.ProductIds.Any() || dataLookupContext.ProductIds.Contains(w.ProductID)); if (dataLookupContext.CustomerId > 0) { totalProducts = totalProducts .Where(os => os.CustomerID == dataLookupContext.CustomerId); } totalProducts = DateFilterOrders_ShoppingCart(dataLookupContext, totalProducts); lookupResult.Int32Result = totalProducts.Any() ? totalProducts.Sum(s => s.Quantity) : 0; lookupResult.StringResult = String.Join(", ", PromotionsData.DataContextProvider .Current .Products .Where(p => dataLookupContext.ProductIds.Contains(p.ProductID)) .Select(p => p.Name).ToArray()); break; case LookupType.TotalProductOrderedAmount: var totalProductAmount = (IQueryable <PromotionsData.Orders_ShoppingCart>)PromotionsData.DataContextProvider .Current .Orders_ShoppingCarts .Where(w => !dataLookupContext.ProductIds.Any() || dataLookupContext.ProductIds.Contains(w.ProductID)); if (dataLookupContext.CustomerId > 0) { totalProductAmount = totalProductAmount.Where(os => os.CustomerID == dataLookupContext.CustomerId); } totalProductAmount = DateFilterOrders_ShoppingCart(dataLookupContext, totalProductAmount) .Where(tpa => tpa.OrderedProductPrice != null); lookupResult.DecimalResult = totalProductAmount.Any() ? (decimal)totalProductAmount.Sum(os => os.OrderedProductPrice) : 0.00M; lookupResult.StringResult = String.Join(", ", PromotionsData.DataContextProvider .Current .Products .Where(p => dataLookupContext.ProductIds.Contains(p.ProductID)).Select(p => p.Name) .ToArray()); break; case LookupType.LastPromotionUsage: var lastPromotionUsages = (IQueryable <PromotionsData.PromotionUsage>)PromotionsData.DataContextProvider .Current .PromotionUsages; if (dataLookupContext.CustomerId > 0) { lastPromotionUsages = lastPromotionUsages .Where(pu => pu.CustomerId == dataLookupContext.CustomerId); } if (dataLookupContext.PromotionId > 0) { lastPromotionUsages = lastPromotionUsages .Where(pu => pu.PromotionId == dataLookupContext.PromotionId); } lastPromotionUsages = DateFilterPromotionUsage(dataLookupContext, lastPromotionUsages); var lastPromotionUsage = lastPromotionUsages .OrderByDescending(pu => pu.DateApplied) .FirstOrDefault(); if (lastPromotionUsage != null) { lookupResult.DateTimeResult = lastPromotionUsage.DateApplied.Value; } else { lookupResult.DateTimeResult = DateTime.MinValue; } break; } return(lookupResult); }
private static IQueryable <PromotionsData.ShoppingCart> SkuFilterShoppingCart(IDataLookupContext dataLookupContext, IQueryable <PromotionsData.ShoppingCart> ShoppingCart) { IQueryable <PromotionsData.ShoppingCart> retVal = ShoppingCart.Where(s => s.CartType == (int)CartTypeEnum.ShoppingCart);; retVal = retVal.Where(s => dataLookupContext.GiftSkus.Contains(s.ProductSKU) || dataLookupContext.GiftProductIds.Contains(s.ProductID)); return(retVal); }
private static IQueryable <PromotionsData.Orders_ShoppingCart> DateFilterOrders_ShoppingCart(IDataLookupContext dataLookupContext, IQueryable <PromotionsData.Orders_ShoppingCart> orders_ShoppingCart) { IQueryable <PromotionsData.Orders_ShoppingCart> retVal = orders_ShoppingCart; DateTime startDate = CalculateQueryDate(dataLookupContext.StartDateType, dataLookupContext.CustomStartDate, dataLookupContext.PromotionId, dataLookupContext.CustomerId); DateTime endDate = CalculateQueryDate(dataLookupContext.EndDateType, dataLookupContext.CustomEndDate, dataLookupContext.PromotionId, dataLookupContext.CustomerId); if (startDate != DateTime.MinValue && endDate != DateTime.MinValue) { retVal = retVal.Where(o => startDate <= o.CreatedOn && o.CreatedOn <= endDate); } return(retVal); }