示例#1
0
        public ActionResult RedeemCoupon(int Id)
        {
            couponService = new CouponService(new DealsDB());

            Coupon cupon = couponService.GetByID(Id);

            if (cupon.CouponValidTill <= DateTime.Now)
            {
                TempData["Message"] = "The deal <b> " + cupon.CouponUniqueText + "</b> you trying to redeeem is already expired";
            }
            else
            {
                if (cupon.ReedemNo < cupon.CouponQty)
                {
                    cupon.ReedemNo = cupon.ReedemNo + 1;
                    couponService.UpdateCoupon(cupon);
                    TempData["Message"] = "The coupon  " + cupon.CouponUniqueText + " is redeemed for " + cupon.ReedemNo + " times";
                }
                else
                {
                    TempData["Message"] = "The coupon " + cupon.CouponUniqueText + " not valid anymore .It was used for " + cupon.ReedemNo + " time already";
                }
            }
            return(RedirectToAction("Coupon"));
        }
示例#2
0
        public void Over1000Off10_AllowReuse_Unlimit()
        {
            var userHasCoupons = new ICoupon[] {
                new TotalAmountCoupon <Guid>()
                {
                    Id              = Guid.NewGuid(),
                    AllowReuse      = true,
                    Threshold       = 1000,
                    DiscountPercent = 10,
                    Name            = "滿1000元九折"
                }
            };

            IOrder order = new TestOrder()
            {
                Items = new List <IOrderItem>(
                    new TestOrderItem[] {
                    new TestOrderItem()
                    {
                        Id    = Guid.NewGuid(),
                        Count = 15,
                        Price = 100,
                        Name  = "衛生紙(12包裝)"
                    }
                }
                    )
            };

            var answer = order.TotalAmount * 0.9m * 0.9m * 0.9m * 0.9m;

            Cashier.Checkout(order, userHasCoupons);

            Assert.Equal(answer, order.TotalAmount);
        }
示例#3
0
 public void ChangeExpiryDate(DateTime dateTime, ICoupon coupon)
 {
     if (dateTime < DateTime.Today)
     {
         coupon.SetCouponState(new InvalidCouponState());
     }
 }
示例#4
0
 public Incentive(string code, ICoupon coupon, DateTime expiresOn)
 {
     this.Code             = code;
     this.Coupon           = coupon;
     this.ExpiresOn        = expiresOn;
     this.MustHaveProducts = new string[0];
 }
        ICoupon GetCoupon(Commerce.Data.SqlRepository.Coupon coupon)
        {
            ICoupon result = null;

            switch (coupon.CouponTypeID)
            {
            //PercentOffOrder
            case 1:
                result = new PercentOffOrderCoupon(coupon.PercentOff);
                break;

            //PercentOffItem
            case 2:
                result = new PercentOffItemCoupon(coupon.PercentOff,
                                                  GetSplitArray(coupon.AppliesToProductCodes));
                break;

            //AmountOffOrder
            case 3:
                result = new AmountOffOrderCoupon(coupon.AmountOff);
                break;

            //AmountOffItem
            case 4:
                result = new AmountOffItemCoupon(coupon.AmountOff,
                                                 GetSplitArray(coupon.AppliesToProductCodes));
                break;
            }

            return(result);
        }
        private static void AssertCouponsInStore(IEnumerable <ICoupon> couponsInStore)
        {
            ICoupon tenPercent     = couponsInStore.First(f => f.Code == "10Percent");
            ICoupon fifteenPercent = couponsInStore.First(f => f.Code == "15Percent");

            Assert.AreEqual("10Percent", tenPercent.Code, "This coupon code should be 10Percent");
            Assert.AreEqual("15Percent", fifteenPercent.Code, "This coupon code should be 15Percent");
        }
 /// <summary>
 /// Kampanya indirimi sonraki tutar; minumum sepet tutarından büyük ve eşitse kupon uygulanır.
 /// </summary>
 /// <param name="coupon"></param>
 public void ApplyCoupon(ICoupon coupon)
 {
     if (TotalPrice >= coupon.MinPurchase)
     {
         double discount = calculateDiscount(TotalPrice, coupon.Rate, coupon.DiscountType);
         TotalPrice    -= discount;
         CouponDiscount = discount;
     }
 }
示例#8
0
        public void SetCouponTest_limit2()
        {
            var productIdA = Guid.NewGuid();
            var productIdB = Guid.NewGuid();

            // 尿布+啤酒省10元
            var userHasCoupons = new ICoupon[] {
                new SetCoupon <Guid, Guid>()
                {
                    Id            = Guid.NewGuid(),
                    Count         = 2,
                    DiscountPrice = 10,
                    Set           = new Dictionary <Guid, uint>()
                    {
                        [productIdA] = 1,
                        [productIdB] = 2
                    },
                    Name = "尿布+兩罐啤酒省10元"
                }
            };

            IOrder order = new TestOrder()
            {
                Items = new List <IOrderItem>(
                    new TestOrderItem[] {
                    new TestOrderItem()
                    {
                        Id    = productIdA,
                        Count = 3,
                        Price = 500,
                        Name  = "尿布"
                    },
                    new TestOrderItem()
                    {
                        Id    = Guid.NewGuid(),
                        Count = 8,
                        Price = 70,
                        Name  = "衛生紙"
                    },
                    new TestOrderItem()
                    {
                        Id    = productIdB,
                        Count = 2,
                        Price = 100,
                        Name  = "啤酒"
                    }
                }
                    )
            };

            var answer = 500 * 3 + 100 * 2 + 70 * 8 - 10 * 1;

            Cashier.Checkout(order, userHasCoupons);

            Assert.Equal(answer, order.TotalAmount);
        }
示例#9
0
        public decimal ComputePrice(IProduct product, ICoupon coupon)
        {
            if (coupon.IsExpired())
            {
                return(product.SellingPrice());
            }
            var discount = product.IsOnSale() ? 0M : (product.SellingPrice() * (coupon.DiscountPercentage() / 100M));

            return(product.SellingPrice() - discount);
        }
示例#10
0
 public ActionResult ShowCoupons()
 {
     if (Session[KeyList.SessionKeys.UserID] != null)
     {
         couponservice = new CouponService(new DealsDB());
         var couponList = couponservice.ViewCoupons(Convert.ToInt32(Session[KeyList.SessionKeys.UserID]));
         return(View(couponList));
     }
     return(RedirectToAction("Index", "Register_Login"));
 }
 /// <summary>
 /// Maps an <see cref="IOfferResult{TConstraint,TAward}"/> to <see cref="ICouponRedemptionResult"/>
 /// </summary>
 /// <param name="attempt">
 /// The attempt.
 /// </param>
 /// <param name="coupon">
 /// The coupon.
 /// </param>
 /// <returns>
 /// The <see cref="ICouponRedemptionResult"/>.
 /// </returns>
 public static ICouponRedemptionResult AsCouponRedemptionResult(this Attempt<IOfferResult<ILineItemContainer, ILineItem>> attempt, ICoupon coupon = null)
 {
     var result = attempt.Success
                      ? new CouponRedemptionResult(attempt.Result.Award, attempt.Result.Messages)
                      : new CouponRedemptionResult(
                            attempt.Exception,
                            attempt.Result != null ? attempt.Result.Messages : null);
     result.Coupon = coupon;
     return result;
 }
示例#12
0
        /// <summary>
        /// Sepete kupon tanımlame methodu
        /// </summary>
        /// <param name="coupon">Kupon</param>
        public void ApplyCoupon(ICoupon coupon)
        {
            var nPrice = coupon.CalculateCoupon(CartPrice);

            if (nPrice != CartPrice)
            {
                _UsedCoupon     = coupon;
                _discountCoupon = CartPrice - nPrice;
                CartPrice       = CartPrice - _discountCoupon;
            }
        }
示例#13
0
 public void ProcessCoupon(ICoupon coupon, IBasket basket, IBasketCoupon basketCoupon)
 {
     if (coupon.MinSpend < basket.BasketTotal())
     {
         basketCoupon.Value             = coupon.Value * (basket.BasketTotal() / 100);
         basketCoupon.CouponCode        = coupon.CouponCode;
         basketCoupon.CouponDescription = coupon.CouponDescription;
         basketCoupon.CouponId          = coupon.CouponId;
         basket.AddBasketCoupon(basketCoupon);
     }
 } //end ProcessCoupon
示例#14
0
        public void ProduceCoupon_WhenCalledForRateCoupon_ReturnsRateCouponObject()
        {
            //Arrange
            CouponFactory factory = new CouponFactory();

            //Act
            ICoupon coupon = factory.ProduceCoupon(50, 10, DiscountType.Rate);

            //Assert
            Assert.IsType <RateCoupon>(coupon);
        }
示例#15
0
        public async Task RemoveCouponByCodeAsync(string couponCode)
        {
            ICoupon coupon = _coupons.Find(o => o.Code == couponCode);

            if (coupon != null)
            {
                _coupons.Remove(coupon);
            }
            // TODO: Remove this demonstration wait.
            await Task.Delay(2000);
        }
示例#16
0
        /// <summary>
        /// applies discount to cart for coupon
        /// </summary>
        /// <param name="coupon"></param>
        public void ApplyCoupon(ICoupon coupon)
        {
            if (coupon is null)
            {
                throw new ArgumentNullException(nameof(coupon));
            }

            if (TotalAmount >= coupon.MinPurchaseAmount)
            {
                CouponDiscount = coupon.GetDiscount(TotalAmount - CampaignDiscount);
            }
        }
示例#17
0
        public decimal ComputePrice(IProduct product, ICoupon coupon)
        {
            var memberBaseDiscount    = product.SellingPrice() * (Discount.BaseMemberDiscount / 100M);
            var memberDiscountedPrice = product.SellingPrice() - memberBaseDiscount;

            if (coupon.IsExpired())
            {
                return(memberDiscountedPrice);
            }

            return(memberDiscountedPrice - (product.SellingPrice() * (coupon.DiscountPercentage() / 100M)));
        }
示例#18
0
        public void ReturnNonMemberDiscountedPrice_WhenNonMemberWithValidCouponForRegularItem()
        {
            // Arrange
            _mockCoupon     = CreateMockCoupon(false, 5);
            _mockProduct    = CreateMockProduct(100M, false);
            _discountScheme = new NonMemberDiscountScheme();

            // Act
            var price = _discountScheme.ComputePrice(_mockProduct, _mockCoupon);

            // Assert
            price.Should().Be(95M);
        }
示例#19
0
        public void ReturnBaseMemberDiscountedPrice_WhenMemberUsesValidCouponForProductAlreadyOnSale()
        {
            // Arrange
            _mockCoupon     = CreateMockCoupon(false, 5);
            _mockProduct    = CreateMockProduct(100M, true);
            _discountScheme = new MemberDiscountScheme();

            // Act
            var price = _discountScheme.ComputePrice(_mockProduct, _mockCoupon);

            // Assert
            price.Should().Be(90M);
        }
示例#20
0
        public void ReturnNoDiscount_WhenNonMemberUsesExpiredCoupon()
        {
            // Arrange
            _mockCoupon     = CreateMockCoupon(true, 5);
            _mockProduct    = CreateMockProduct(100M, false);
            _discountScheme = new NonMemberDiscountScheme();

            // Act
            var price = _discountScheme.ComputePrice(_mockProduct, _mockCoupon);

            // Assert
            price.Should().Be(100M);
        }
示例#21
0
        public SwapLeg(Date startDate,
                       Date maturityDate,
                       double notional,
                       bool notionalExchange,
                       CurrencyCode currency,
                       ICoupon coupon,
                       ICalendar calendar,
                       Frequency paymentFreq,
                       Stub paymentStub,
                       IDayCount dayCount,
                       BusinessDayConvention paymentBda,
                       DayGap settlementGap   = null,
                       Date firstPaymenetDate = null,
                       Date terminationDate   = null,
                       double terminateAmount = double.NaN
                       )
        {
            StartDate = startDate;
            UnderlyingMaturityDate = maturityDate;
            Notional          = notional;
            NotionalExchange  = notionalExchange;
            Currency          = currency;
            Coupon            = coupon;
            Calendar          = calendar;
            PaymentFreq       = paymentFreq;
            PaymentStub       = paymentStub;
            DayCount          = dayCount;
            PaymentBda        = paymentBda;
            SettlmentGap      = settlementGap ?? new DayGap("+0BD");
            FirstPaymentDate  = firstPaymenetDate;
            TerminationDate   = terminationDate;
            TerminationAmount = terminateAmount;

            if (FirstPaymentDate != null)
            {
                var temp = new Schedule(FirstPaymentDate, UnderlyingMaturityDate, PaymentFreq.GetTerm(), PaymentStub, Calendar, PaymentBda);
                Accruals = new Schedule(new[] { StartDate }.Union(temp));
            }
            else
            {
                Accruals = new Schedule(StartDate, UnderlyingMaturityDate, PaymentFreq.GetTerm(), PaymentStub, Calendar, PaymentBda);
            }

            if (TerminationDate != null)
            {
                Accruals = new Schedule(Accruals.Where(x => x < TerminationDate));
            }

            PaymentSchedule = new Schedule(Accruals.Skip(1));
        }
示例#22
0
        //Factory method pattern
        public ICoupon ProduceCoupon(double minPurchaseAmount, double discount, DiscountType discountType)
        {
            ICoupon coupon = null;

            switch (discountType)
            {
            case DiscountType.Amount:
                coupon = new AmountCoupon(minPurchaseAmount, discount, discountType);
                break;

            case DiscountType.Rate:
                coupon = new RateCoupon(minPurchaseAmount, discount, discountType);
                break;
            }
            return(coupon);
        }
示例#23
0
        public async Task AddCouponByCodeAsync(string couponCode)
        {
            if (_coupons.Find(o => o.Code == couponCode) != null)
            {
                throw new ArgumentException("Coupon code is already used.");
            }
            else
            {
                ICoupon coupon = await _couponService.GetByCodeAsync(couponCode);

                if (coupon == null)
                {
                    throw new ArgumentException("Invalid coupon code.");
                }
                await AddCouponAsync(coupon);
            }
        }
示例#24
0
        public ICoupon Get(double minCartAmount, double campaignValue, CouponTypes campaignTypes)
        {
            ICoupon coupon = null;

            switch (campaignTypes)
            {
            case CouponTypes.Amount:
                coupon = new AmountCoupon(campaignValue, minCartAmount);
                break;

            case CouponTypes.Rate:
                coupon = new RateCoupon(campaignValue, minCartAmount);
                break;
            }

            return(coupon);
        }
示例#25
0
        public void AdditionalPurchasePriceCoupon_Limit()
        {
            var TargetProductId = Guid.NewGuid();

            // 每兩件折價50
            var userHasCoupons = new ICoupon[] {
                new AdditionalPurchasePriceCoupon <Guid, Guid>()
                {
                    Id            = Guid.NewGuid(),
                    Count         = 2,
                    TargetAmount  = 1000,
                    DiscountPrice = 10,
                    Targets       = new List <Guid>(new Guid[] { TargetProductId }),
                    Name          = "滿1000元加購啤酒便宜10元"
                }
            };

            IOrder order = new TestOrder()
            {
                Items = new List <IOrderItem>(
                    new TestOrderItem[] {
                    new TestOrderItem()
                    {
                        Id    = Guid.NewGuid(),
                        Count = 15,
                        Price = 100,
                        Name  = "衛生紙(12包裝)"
                    },
                    new TestOrderItem()
                    {
                        Id    = TargetProductId,
                        Count = 10,
                        Price = 50,
                        Name  = "啤酒"
                    }
                }
                    )
            };

            var answer = 100 * 15 + 50 * 10 - 10 * 2;

            Cashier.Checkout(order, userHasCoupons);

            Assert.Equal(answer, order.TotalAmount);
        }
示例#26
0
        public void SecondHalfPrice_Unlimit()
        {
            var TargetProductId = Guid.NewGuid();

            // 每兩件折價50
            var userHasCoupons = new ICoupon[] {
                new QuantituDiscountCoupon <Guid, Guid>()
                {
                    Id = Guid.NewGuid(),
                    DiscountQuantity = 2,
                    DiscountPrice    = 100m * 0.5m,
                    Targets          = new List <Guid>(new Guid[] { TargetProductId }),
                    Name             = "衛生紙第二件半價"
                }
            };

            IOrder order = new TestOrder()
            {
                Items = new List <IOrderItem>(
                    new TestOrderItem[] {
                    new TestOrderItem()
                    {
                        Id    = TargetProductId,
                        Count = 5,
                        Price = 100,
                        Name  = "衛生紙(12包裝)"
                    },
                    new TestOrderItem()
                    {
                        Id    = TargetProductId,
                        Count = 10,
                        Price = 100,
                        Name  = "衛生紙(12包裝)"
                    }
                }
                    )
            };

            var answer = (100 + 50) * 7 + 100;

            Cashier.Checkout(order, userHasCoupons);

            Assert.Equal(answer, order.TotalAmount);
        }
示例#27
0
        public decimal CalculateTotal(ICoupon coupon, Dictionary <string, IOffer> currentOffers)
        {
            var total = Products.Sum(kv =>
            {
                var product  = kv.Value.Product;
                var quantity = kv.Value.Quantity;
                if (currentOffers != null && currentOffers.ContainsKey(product.Name))
                {
                    return(currentOffers[product.Name].ApplyOffer(product, quantity));
                }
                return(product.Price * quantity);
            });

            if (coupon != null)
            {
                return(coupon.ApplyDiscount(total));
            }

            return(total);
        }
示例#28
0
        void ApplyCouponDiscount(IEnumerable <ICoupon> coupons)
        {
            if (coupons != null && coupons.Any())
            {
                ICoupon bestCoupon = default(ICoupon);

                double bestCouponDiscountAmount = default(double);

                foreach (var coupon in coupons)
                {
                    if (this.IsCouponApplicable(coupon))
                    {
                        var totalDiscountAmount = this.GetCouponDiscountAmount(coupon);

                        if (totalDiscountAmount > bestCouponDiscountAmount)
                        {
                            bestCouponDiscountAmount = totalDiscountAmount;
                            bestCoupon = coupon;
                        }
                    }
                }

                if (bestCoupon != default(ICoupon))
                {
                    this.AppliedCoupon = bestCoupon;
                    this.ApplyDiscountOnCartItems(this.Items, bestCouponDiscountAmount);
                }
                else
                {
                    this.AppliedCoupon = null;
                }

                this.TotalCouponDiscountAmount = bestCouponDiscountAmount;
                this.UpdateAmounts();
            }
            else
            {
                this.TotalAmountAfterDiscounts = this.TotalAmountAfterCampaignDiscount;
                this.UpdateAmounts();
            }
        }
示例#29
0
        double GetCouponDiscountAmount(ICoupon coupon)
        {
            double discountAmount;

            if (coupon is IAmountCoupon)
            {
                var amountCoupon = coupon as IAmountCoupon;

                discountAmount = amountCoupon.DiscountAmount;
            }
            else if (coupon is IRateCoupon)
            {
                var rateCoupon = coupon as IRateCoupon;

                discountAmount = rateCoupon.DiscountRate * this.TotalAmountAfterCampaignDiscount;
            }
            else
            {
                throw new NotImplementedException();
            }

            return(discountAmount);
        }
 public ICoupon UpdateCoupon(ICoupon Coupon)
 {
     throw new NotImplementedException();
 }
示例#31
0
 public Incentive(string code, ICoupon coupon, DateTime expiresOn) {
     this.Code = code;
     this.Coupon = coupon;
     this.ExpiresOn = expiresOn;
     this.MustHaveProducts = new string[0];
 }
示例#32
0
 /// <summary>
 /// Method for comparing one coupon to another
 /// </summary>
 public int CompareTo(ICoupon other)
 {
     return(AmountInCents.CompareTo(other.AmountInCents));
 }
示例#33
0
 bool IsCouponApplicable(ICoupon coupon)
 {
     return(coupon.IsActive &&
            (!coupon.HasMinCartAmountConstraint || (coupon.HasMinCartAmountConstraint && this.TotalAmountAfterCampaignDiscount >= coupon.MinCartAmount)) &&
            (!coupon.HasMinCartItemQuantityConstraint || (coupon.HasMinCartItemQuantityConstraint && GetTotalQuantity() >= coupon.MinCartItemQuantity)));
 }
 /// <summary>
 /// Serialized and stores the coupon into the <see cref="ExtendedDataCollection"/>
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <param name="coupon">
 /// The coupon.
 /// </param>
 internal static void SetCouponValue(this ExtendedDataCollection extendedData, ICoupon coupon)
 {
     extendedData.SetValue(
         Core.Constants.ExtendedDataKeys.CouponReward,
         JsonConvert.SerializeObject(((Coupon)coupon).Settings.ToOfferSettingsDisplay()));
 }
		public void Save(ICoupon coupon)
		{
			var sqlHelper = DataLayerHelper.CreateSqlHelper(GlobalSettings.DbDSN);

			sqlHelper.ExecuteNonQuery("update [uWebshopCoupons] set NumberAvailable = @NumberAvailable WHERE DiscountId = @DiscountId and CouponCode = @CouponCode", sqlHelper.CreateParameter("@DiscountId", coupon.DiscountId), sqlHelper.CreateParameter("@CouponCode", coupon.CouponCode), sqlHelper.CreateParameter("@NumberAvailable", coupon.NumberAvailable));
		}
示例#36
0
        private List<CouponEntryData> GetTaxonomyList()
        {
            //instantiate coupon service field
            _CouponService = _CouponService == null ? new Coupon(_CouponApi.RequestInformationRef) : _CouponService;

            // taxonomies
            Criteria<CouponEntryProperty> taxonomyCriteria = new Criteria<CouponEntryProperty>();
            taxonomyCriteria.AddFilter(CouponEntryProperty.CouponId, CriteriaFilterOperator.EqualTo, this.CouponPublishedData.Id);
            taxonomyCriteria.AddFilter(CouponEntryProperty.IsIncluded, CriteriaFilterOperator.EqualTo, this.Scope == CouponScope.Exclude ? false : true);
            List<CouponEntryData> taxonomyList = _CouponService.GetTaxonomyList(taxonomyCriteria);

            return taxonomyList;
        }
 public ICoupon CreateCoupon(ICoupon Coupon, int ProductFamilyID)
 {
     throw new NotImplementedException();
 }