Example #1
0
        public static void FinalizePromotionsOnOrderComplete(ShoppingCart cart, int orderNumber)
        {
            foreach (IDiscountResult result in cart.DiscountResults)
            {
                PromotionsData.PromotionUsage promotionUsage = PromotionsData.DataContextProvider.Current.PromotionUsages
                                                               .FirstOrDefault(pu => pu.PromotionId == result.Promotion.Id && pu.Complete == false && pu.CustomerId == cart.ThisCustomer.CustomerID);
                if (promotionUsage == null)
                {
                    continue;
                }

                promotionUsage.OrderId                = orderNumber;
                promotionUsage.DateApplied            = DateTime.Now;
                promotionUsage.LineItemDiscountAmount = result.LineItemTotal;
                promotionUsage.ShippingDiscountAmount = result.ShippingTotal;
                promotionUsage.OrderDiscountAmount    = result.OrderTotal;
                promotionUsage.DiscountAmount         = result.TotalDiscount;
                promotionUsage.Complete               = true;

                PromotionsData.DataContextProvider.Current.SubmitChanges();
            }

            //Make sure we clear out the auto assigned list.
            PromotionManager.ResetAutoAssignedPromotionList(cart.ThisCustomer.CustomerID);
        }
Example #2
0
 public static void AssignPromotion(int customerId, int promotionId)
 {
     PromotionsData.PromotionUsage promotionUsage = GetPromotionUsagesByCustomer(customerId).FirstOrDefault(pu => pu.PromotionId == promotionId);
     if (promotionUsage == null)
     {
         promotionUsage = new PromotionsData.PromotionUsage
         {
             CustomerId = customerId,
         };
         PromotionsData.DataContextProvider.Current.PromotionUsages.InsertOnSubmit(promotionUsage);
     }
     promotionUsage.PromotionId = promotionId;
     PromotionsData.DataContextProvider.Current.SubmitChanges();
 }
Example #3
0
        private static IDataLookupResult PromotionController_OnLookupData(IDataLookupContext dataLookupContext)
        {
            IDataLookupResult lookupResult = new SimpleDataLookupResult();

            switch (dataLookupContext.LookupType)
            {
            case LookupType.TotalPromotionUses:
                IQueryable <PromotionsData.PromotionUsage> 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.TotalPromotionDiscounts:
                IQueryable <PromotionsData.PromotionUsage> promotionUsageDiscount = PromotionsData.DataContextProvider.Current.PromotionUsages.Where(pu => pu.Complete);

                if (dataLookupContext.CustomerId > 0)
                {
                    promotionUsageDiscount = promotionUsageDiscount.Where(pu => pu.CustomerId == dataLookupContext.CustomerId);
                }

                if (dataLookupContext.PromotionId > 0)
                {
                    promotionUsageDiscount = promotionUsageDiscount.Where(pu => pu.PromotionId == dataLookupContext.PromotionId);
                }

                promotionUsageDiscount     = DateFilterPromotionUsage(dataLookupContext, promotionUsageDiscount).Where(pud => pud.DiscountAmount != null);
                lookupResult.DecimalResult = promotionUsageDiscount.Any() ? (decimal)promotionUsageDiscount.Sum(pu => pu.DiscountAmount) : 0.00M;
                break;

            case LookupType.TotalOrders:
                IQueryable <PromotionsData.Order> totalOrders = 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:
                IQueryable <PromotionsData.Order> totalOrderAmount = 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:
                IQueryable <PromotionsData.Orders_ShoppingCart> totalProducts = 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:
                IQueryable <PromotionsData.Orders_ShoppingCart> totalProductAmount = 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.TotalCostForSkus:
                IQueryable <PromotionsData.ShoppingCart> totalCostForSkus = PromotionsData.DataContextProvider.Current.ShoppingCarts.Where(s => s.CartType == (int)CartTypeEnum.ShoppingCart);
                if (dataLookupContext.CustomerId > 0)
                {
                    totalCostForSkus = totalCostForSkus.Where(os => os.CustomerID == dataLookupContext.CustomerId);
                }

                totalCostForSkus           = SkuFilterShoppingCart(dataLookupContext, totalCostForSkus).Where(sfsc => sfsc.ProductPrice != null);
                lookupResult.DecimalResult = totalCostForSkus.Any() ? (decimal)totalCostForSkus.Sum(s => s.ProductPrice) : 0.00M;
                break;

            case LookupType.TotalPromotions:
                IQueryable <PromotionsData.PromotionUsage> totalPromotionUsages = PromotionsData.DataContextProvider.Current.PromotionUsages.Where(pu => pu.Complete);

                if (dataLookupContext.CustomerId > 0)
                {
                    totalPromotionUsages = totalPromotionUsages.Where(pu => pu.CustomerId == dataLookupContext.CustomerId);
                }

                if (dataLookupContext.PromotionId > 0)
                {
                    totalPromotionUsages = totalPromotionUsages.Where(pu => pu.PromotionId == dataLookupContext.PromotionId);
                }

                totalPromotionUsages     = DateFilterPromotionUsage(dataLookupContext, totalPromotionUsages);
                lookupResult.Int32Result = totalPromotionUsages.Count();
                break;

            case LookupType.LastPromotionUsage:
                IQueryable <PromotionsData.PromotionUsage> lastPromotionUsages = 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);
                PromotionsData.PromotionUsage lastPromotionUsage = lastPromotionUsages.OrderByDescending(pu => pu.DateApplied).FirstOrDefault();
                if (lastPromotionUsage != null)
                {
                    lookupResult.DateTimeResult = lastPromotionUsage.DateApplied.Value;
                }
                else
                {
                    lookupResult.DateTimeResult = DateTime.MinValue;
                }
                break;
            }

            return(lookupResult);
        }