// GET api/values
        public IEnumerable <CouponViewModel> Get()
        {
            CouponCode.CouponCodeBuilder couponBuilder = new CouponCode.CouponCodeBuilder();
            CouponCode.Options           opt           = new CouponCode.Options();
            string couponCode = couponBuilder.Generate(opt);

            IList <CouponViewModel> listCouponViewModel = new List <CouponViewModel>();

            using (PatuhEntities db = new PatuhEntities())
            {
                IList <MsCoupon> couponList = db.MsCoupons.OrderBy(x => x.Id).ToList();

                if (couponList != null && couponList.Count > 0)
                {
                    foreach (MsCoupon coupon in couponList)
                    {
                        CouponViewModel row = new CouponViewModel();
                        row.Id          = coupon.Id;
                        row.Title       = coupon.Title;
                        row.Benefit     = coupon.Benefit;
                        row.Usage       = coupon.Usage;
                        row.Tnc         = coupon.Tnc;
                        row.PointNeeded = coupon.PointNeeded ?? 0;
                        row.ValidUntil  = coupon.ValidUntil;
                        //row.CouponImage = coupon.CouponImage;
                        row.cStatus      = coupon.cStatus;
                        row.cCreated     = coupon.cCreated;
                        row.dCreated     = coupon.dCreated;
                        row.cLastUpdated = coupon.cLastUpdated;
                        row.dLastUpdated = coupon.dLastUpdated;

                        listCouponViewModel.Add(row);
                    }
                }

                return(listCouponViewModel);
            }
        }
        // POST api/values
        public object Post()
        {
            JsonResultViewModel result = new JsonResultViewModel();

            result.status      = true;
            result.message     = "Coupon successfully claimed";
            result.messageCode = "S";

            var    httpRequest = HttpContext.Current.Request;
            long   id          = string.IsNullOrEmpty(httpRequest["msCouponId"]) ? 0 : long.Parse(httpRequest["msCouponId"]);
            string userId      = httpRequest["UserId"];


            try
            {
                using (PatuhEntities db = new PatuhEntities())
                {
                    MsCoupon msCoupon = db.MsCoupons.Where(x => x.Id == id).FirstOrDefault();

                    long totalPoint = db.TrPoints.Where(x => x.UserID == userId).Sum(x => x.PointValue) ?? 0;

                    if ((totalPoint - msCoupon.PointNeeded) < 0)
                    {
                        result.status      = false;
                        result.message     = "User Points is not enough to claim the coupon";
                        result.messageCode = "Error in claiming Coupon";
                        return(result);
                    }

                    TrUserCoupon userCoupon = db.TrUserCoupons.Where(x => x.MsCouponId == id).FirstOrDefault();

                    if (userCoupon == null)
                    {
                        CouponCode.CouponCodeBuilder couponBuilder = new CouponCode.CouponCodeBuilder();
                        CouponCode.Options           opt           = new CouponCode.Options();
                        string couponCode = couponBuilder.Generate(opt);

                        userCoupon            = new TrUserCoupon();
                        userCoupon.MsCouponId = id;
                        userCoupon.UserID     = userId;
                        userCoupon.CouponCode = couponCode;
                        userCoupon.cCreated   = userId;
                        userCoupon.dCreated   = DateTime.Now;
                        db.TrUserCoupons.AddObject(userCoupon);

                        TrPoint trPoint = new TrPoint();
                        trPoint.ArticleId    = 0;
                        trPoint.UserID       = userId;
                        trPoint.ActionCode   = "CLAIM";
                        trPoint.PointValue   = (msCoupon.PointNeeded * -1);
                        trPoint.cCreated     = userId;
                        trPoint.dCreated     = DateTime.Now;
                        trPoint.cLastUpdated = userId;
                        trPoint.dLastUpdated = DateTime.Now;

                        db.TrPoints.AddObject(trPoint);
                    }

                    userCoupon.cStatus = "Y";

                    /*
                     * if (httpRequest.Files.Count > 0)
                     *  {
                     *
                     *      foreach (string file in httpRequest.Files)
                     *      {
                     *          var postedFile = httpRequest.Files[file];
                     *          Type fileType = postedFile.GetType();
                     *          byte[] couponImage = new byte[postedFile.ContentLength];
                     *
                     *          postedFile.InputStream.Read(couponImage, 0, postedFile.ContentLength);
                     *          userCoupon.c
                     *      }
                     */
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result.status      = false;
                result.message     = e.Message;
                result.messageCode = "Error in claiming Coupon";
            }

            return(result);
        }