Beispiel #1
0
        private static string ToDescriptionString(this coupon c, Currency currency)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("<div class='bold'>{0}</div>", c.description);
            if (c.maxImpressions.HasValue)
            {
                sb.AppendFormat("<span class='info_tag' title='max impressions'>max {0} impressions</span>",
                                c.maxImpressions.Value);
            }
            else
            {
                sb.Append("<span class='info_tag' title='unlimited use'>unlimited</span>");
            }

            if (c.minimumPurchase.HasValue)
            {
                sb.AppendFormat("<span class='info_tag'>min {0}{1}</span>", currency.symbol,
                                c.minimumPurchase.Value.ToString("n" + currency.decimalCount));
            }



            return(sb.ToString());
        }
Beispiel #2
0
 private static string ToValueString(this coupon c, Currency currency)
 {
     if (c.couponValue.HasValue)
     {
         return(string.Concat(currency.symbol, c.couponValue.Value.ToString("n" + currency.decimalCount)));
     }
     if (c.couponPercentage.HasValue)
     {
         return(string.Format("{0}%", c.couponPercentage.Value.ToString("n2")));
     }
     return("No Value");
 }
Beispiel #3
0
        public object GetCoupon(coupon _coupon)
        {
            //รับเลข req_couponnumble ที่ส่งมาจาก API
            var objData = this.LoadCoupon(_coupon.couponjob, _coupon.type);

            if (objData != null)
            {
                if ((int)objData[0] == 1)
                {
                    return(Json(new { id = objData[0], type = objData[1], code_coupon = objData[2], coupon_end_date = objData[3] }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { id = objData[0], type = objData[1], msg = objData[2] }, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json(new { id = 3 }, JsonRequestBehavior.AllowGet));
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your choice");
            int options = Convert.ToInt32(Console.ReadLine());

            switch (options)
            {
            case 1:
                Replace aclass = new Replace();
                aclass.replace();
                break;

            case 2:
                coinToss bclass = new coinToss();
                bclass.coins();
                break;

            case 3:
                leapYear cclass = new leapYear();
                cclass.leap();
                break;

            case 4:
                powerTwo dclass = new powerTwo();
                dclass.power();
                break;

            case 5:
                factor eclass = new factor();
                eclass.primes();
                break;

            case 6:
                Harmonic fclass = new Harmonic();
                fclass.harnum();
                break;

            case 7:
                Distance gclass = new Distance();
                gclass.dist();
                break;

            case 8:
                windchill hclass = new windchill();
                hclass.wind();
                break;

            case 9:
                quadricEquation iclass = new quadricEquation();
                iclass.equation();
                break;

            case 10:
                sumOfThree jclass = new sumOfThree();
                jclass.integer();
                break;

            case 11:
                Gambler kclass = new Gambler();
                kclass.Game();
                break;

            case 12:
                swatch lclass = new swatch();
                lclass.watch();
                break;

            case 13:
                coupon mclass = new coupon();
                mclass.number();
                break;

            case 14:
                TwoDArray nclass = new TwoDArray();
                nclass.array2D();
                break;

            case 15:
                TIC_TAC_TOE oclass = new TIC_TAC_TOE();
                oclass.tok();
                break;
            }
        }
Beispiel #5
0
        public ActionResult Create(string code, string description, DurationType duration_type, string end_date,
                                   string start_date, bool hasDuration, int?maxImpressions, bool minimumPurchaseOnly, decimal?minimumPurchase,
                                   decimal value, string valuetype)
        {
            // check required fields
            if (string.IsNullOrEmpty(code))
            {
                return(SendJsonErrorResponse("Coupon code not specified"));
            }
            if (string.IsNullOrEmpty(description))
            {
                return(SendJsonErrorResponse("Coupon description not specified"));
            }
            if (valuetype == "%" && value > 100)
            {
                return(SendJsonErrorResponse("Discount cannot be more than 100%"));
            }

            DateTime startdate;
            DateTime?expirydate = null;

            if (!string.IsNullOrEmpty(start_date))
            {
                startdate = DateTime.ParseExact(start_date, GeneralConstants.DATEFORMAT_STANDARD,
                                                CultureInfo.InvariantCulture);
            }
            else
            {
                startdate = DateTime.UtcNow;
            }

            if (!string.IsNullOrEmpty(end_date))
            {
                expirydate = DateTime.ParseExact(end_date, GeneralConstants.DATEFORMAT_STANDARD,
                                                 CultureInfo.InvariantCulture);
            }

            if (expirydate.HasValue && expirydate.Value <= startdate)
            {
                return(SendJsonErrorResponse("End date is earlier than start date"));
            }

            // check if coupon with same code already exist
            var coupon = repository.GetCoupons(subdomainid.Value).Where(x => x.code == code).SingleOrDefault();

            if (coupon != null)
            {
                return(SendJsonErrorResponse("Coupon code already in use"));
            }

            // now we fill up coupon
            coupon = new coupon
            {
                subdomainid = subdomainid.Value,
                code        = code.StripWhitespace(),
                description = description,
                impressions = 0,
                expired     = DateTime.UtcNow < startdate? true:false,
                startDate   = startdate
            };
            switch (duration_type)
            {
            case DurationType.UNLIMITED:
                break;

            case DurationType.IMPRESSION:
                coupon.maxImpressions = maxImpressions;
                break;

            default:
                break;
            }
            if (minimumPurchaseOnly)
            {
                coupon.minimumPurchase = minimumPurchase;
            }
            if (valuetype == "%")
            {
                coupon.couponPercentage = value;
            }
            else
            {
                coupon.couponValue = value;
            }

            if (hasDuration)
            {
                coupon.expiryDate = expirydate.Value;
            }
            try
            {
                repository.AddCoupon(coupon);
            }
            catch (Exception ex)
            {
                return(SendJsonErrorResponse(ex));
            }

            return(Json("Coupon added".ToJsonOKMessage()));
        }
Beispiel #6
0
 public void DeleteCoupon(coupon coupon)
 {
     db.coupons.DeleteOnSubmit(coupon);
     db.SubmitChanges();
 }
Beispiel #7
0
 public void AddCoupon(coupon coupon)
 {
     db.coupons.InsertOnSubmit(coupon);
     db.SubmitChanges();
 }