예제 #1
0
        public ActionResult GetCouponAdd(string code, string medium, string exDate, string frid)
        {
            tbl_coupon Addcoupon = new tbl_coupon();

            if (frid != "" || frid != null)
            {
                if (exDate != "")
                {
                    Addcoupon.ExpirationDate = Convert.ToDateTime(exDate);
                }
                else
                {
                    Addcoupon.ExpirationDate = DateTime.Now;
                }
                int frId = Convert.ToInt32(frid);
                Addcoupon.Code            = code;
                Addcoupon.MarketingMedium = medium;
                Addcoupon.FranchiseID     = frId;
                dbeight.tbl_coupon.AddObject(Addcoupon);
                dbeight.SaveChanges();
            }

            return(Json(string.Empty));
        }
예제 #2
0
        public ActionResult SaveCouponCode(tbl_coupon[] datas)
        {
            int?frId = datas[0].FranchiseID;

            for (int i = 0; i < datas.Count(); i++)
            {
                var code = datas[i].Code;

                if (datas[i].CouponID == 0)
                {
                    if (dbeight.tbl_coupon.Any(q => q.Code == code))
                    {
                        return(Json("duplicate"));
                    }
                }
                else
                {
                    int cid = datas[i].CouponID;

                    if (dbeight.tbl_coupon.Any(q => q.Code == code && q.CouponID != cid))
                    {
                        return(Json("duplicate"));
                    }
                }
            }

            for (int i = 0; i < datas.Count(); i++)
            {
                if (datas[i].CouponID == 0)
                {
                    dbeight.tbl_coupon.AddObject(datas[i]);
                    dbeight.SaveChanges();
                }
                else
                {
                    int cid = datas[i].CouponID;

                    tbl_coupon data = dbeight.tbl_coupon.First(q => q.CouponID == cid);

                    data.Code            = datas[i].Code;
                    data.MarketingMedium = datas[i].MarketingMedium;
                    data.DiscountAmount  = datas[i].DiscountAmount;
                    data.Percentage      = datas[i].Percentage;
                    data.ExpirationDate  = datas[i].ExpirationDate;

                    dbeight.SaveChanges();
                }
            }

            var coupon = dbeight.tbl_coupon.Where(q => q.FranchiseID == frId).ToList();

            var coupon_list = from c in coupon
                              select new
            {
                CouponID        = c.CouponID,
                Code            = c.Code,
                DiscountAmount  = c.DiscountAmount,
                Percentage      = c.Percentage,
                MarketingMedium = c.MarketingMedium,
                ExpirationDate  = c.ExpirationDate.HasValue ? c.ExpirationDate.Value.ToShortDateString() : ""
            };

            return(Json(coupon_list));
        }