Exemplo n.º 1
0
        public JsonResult Create([System.Web.Http.FromBody] CouponModel m)
        {
            List <CouponResponseModel> response = new List <CouponResponseModel>();

            try
            {
                m.name       = m.name?.Trim() ?? "";
                m.couponcode = m.couponcode?.Trim() ?? "";
                if (m.couponcode.HasValue())
                {
                    if (CouponModel.IsExisting(m.couponcode))
                    {
                        response.Add(new CouponResponseModel {
                            Message = "code already exists"
                        });
                        return(Json(response, JsonRequestBehavior.AllowGet));
                    }
                }

                m.CreateCoupon();
                response.Add(new CouponResponseModel {
                    Message = "Ok"
                });
            }
            catch (Exception ex)
            {
                response.Add(new CouponResponseModel {
                    Message = ex.Message
                });
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
 public ActionResult Create(CouponModel m)
 {
     if (m.couponcode.HasValue())
     {
         if (CouponModel.IsExisting(m.couponcode))
         {
             return(Content("code already exists"));
         }
     }
     m.CreateCoupon();
     return(View(m));
 }