Esempio n. 1
0
        public ActionResult GenerateCode(int?id)
        {
            Models.PromotionCodes promotionCodes = new PromotionCodes();
            if (id == null)
            {
                Random generator = new Random();
                string promoCode = generator.Next(0, 999999).ToString("D6");
                TempData["PromoCode"]     = promoCode;
                promotionCodes.Code       = promoCode;
                promotionCodes.ExpiryDate = DateTime.Now;
            }
            else
            {
                ViewModel.PromotionCodes.PromotionCodes promo = new ViewModel.PromotionCodes.PromotionCodes();
                promotionCodes            = promo.GetPromoCodeById(id);
                promotionCodes.ExpiryDate = promotionCodes.ExpiryDate.Date;
            }


            return(View(promotionCodes));
        }
Esempio n. 2
0
    public static object AddPromotionCode(String promotionCode, Double lineTip, Double deliveryCharges)
    {
        #region Variables

        string json = @"{{'SubTotal':{0},'Tax': {1}, 'OrderTotal': {2}, 'InvalidCode': {3} }}";

        Double deduction = 0, NewTotal = 0, Tax = 0;
        PromotionCodeManager promoManager  = new PromotionCodeManager();
        BranchManager        branchManager = new BranchManager();
        JavaScriptSerializer serializer    = new JavaScriptSerializer();

        #endregion

        PromotionCodes code                = promoManager.GetPromotionCodeByCode(promotionCode);
        Branches       branch              = branchManager.GetBranchById(BranchId);
        if (code != null)
        {
            DateTime currentDate = DateTime.Now;

            NewTotal = SessionUserOrder.OrderTotal;
            Tax      = ((NewTotal + deliveryCharges) * Convert.ToDouble(branch.TaxPercentage)) / 100;

            double preOrderPromoValue = 0.0d;

            if (SessionPreOrderPromo != null)
            {
                preOrderPromoValue = SessionPreOrderPromo.PreOrderPromoValue;

                if (SessionPreOrderPromo.PreOrderPromoCode.ToLower().Equals(promotionCode.ToLower()))
                {
                    json = string.Format(json, SessionUserOrder.OrderTotal, Tax,
                                         (SessionUserOrder.OrderTotal + deliveryCharges + Tax + lineTip),
                                         Resources.ErrorMessages.PromoCodeInUse);
                }

                return(serializer.Deserialize <Dictionary <string, string> >(json));
            }

            if (currentDate > code.EndDate || currentDate < code.StartDate)
            {
                json = string.Format(json, SessionUserOrder.OrderTotal, Tax, (SessionUserOrder.OrderTotal + deliveryCharges + Tax + lineTip), Resources.ErrorMessages.PromoOutOfDate);

                return(serializer.Deserialize <Dictionary <string, string> >(json));
            }

            if (code.TypeOfPromotion == PromotionType.EGiftCard && code.CodeUsageCounter != null && code.CodeUsageCounter == 0)    //  in db it's incrementing
            {
                json = string.Format(json, SessionUserOrder.OrderTotal, Tax, (SessionUserOrder.OrderTotal + Tax + lineTip), Resources.ErrorMessages.PromoCounterZero);

                return(serializer.Deserialize <Dictionary <string, string> >(json));
            }

            if (code.TypeOfPromotion == PromotionType.Money)
            {
                deduction = code.PromotionValue;
            }
            else if (code.TypeOfPromotion == PromotionType.EGiftCard)
            {
                if ((code.PromotionValue - code.PromoValueUsed) > 0)
                {
                    if (SessionUserOrder.OrderTotal < (code.PromotionValue - code.PromoValueUsed))
                    {
                        code.PromoValueUsed += deduction = SessionUserOrder.OrderTotal;
                    }
                    else
                    {
                        code.PromoValueUsed += deduction = (code.PromotionValue - code.PromoValueUsed);
                    }
                }
                else
                {       // promo value used completely
                    json = string.Format(json, NewTotal, Tax, (NewTotal + deliveryCharges + Tax + lineTip), Resources.ErrorMessages.PromoCodeBalanceEnded);
                    return(serializer.Deserialize <Dictionary <string, string> >(json));
                }
            }
            else
            {
                deduction = (SessionUserOrder.OrderTotal * code.PromotionValue) / 100;
            }

            NewTotal = SessionUserOrder.OrderTotal;
            NewTotal = NewTotal <= 0 ? 0 : NewTotal;
            Tax      = ((NewTotal + deliveryCharges) * Convert.ToDouble(branch.TaxPercentage)) / 100;

            json = string.Format(json, NewTotal, Tax, (NewTotal + deliveryCharges + Tax + lineTip) - deduction, 0);

            var dict = serializer.Deserialize <Dictionary <string, string> >(json);

            return(dict);
        }
        else
        {
            SessionPreOrderPromo = null;
            Tax  = (SessionUserOrder.OrderTotal + deliveryCharges) * (Convert.ToDouble(branch.TaxPercentage)) / 100;
            json = string.Format(json, SessionUserOrder.OrderTotal, Tax, SessionUserOrder.OrderTotal + deliveryCharges + Tax + lineTip, Resources.ErrorMessages.PromoCodeInvalid);


            var dict = serializer.Deserialize <Dictionary <string, string> >(json);
            return(dict);
        }
    }
Esempio n. 3
0
 public ActionResult addcode(PromotionCodes pc)
 {
     return(Ok(code.addpromcode(pc)));
 }