Esempio n. 1
0
 public JsonResult Modify(Voucher model)
 {
     try
     {
         if (model.Id == 0)
         {
             model.CreateDate = DateTime.Now;
             VoucherService.InsertVoucher(model);
         }
         else
         {
             var update = VoucherService.GetVoucher(model.Id);
             update.Linked_SiteId = model.Linked_SiteId;
             update.VoucherName   = model.VoucherName;
             update.Body          = model.Body;
             update.EndDate       = model.EndDate;
             update.Flag          = model.Flag;
             VoucherService.UpdateVoucher(update);
         }
         VoucherService.Save();
         return(Json(new MessageResults {
             Status = "Success"
         }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(new MessageResults {
             Status = "Error"
         }, JsonRequestBehavior.AllowGet));
     }
 }
Esempio n. 2
0
        public string UpdateVoucher(ref AddEditVoucherViewModel viewModel)
        {
            var voucher = new Voucher();

            VoucherService.UpdateVoucher(voucher);
            return(null);
        }
Esempio n. 3
0
        public IHttpActionResult PutVoucherModel(int id, VoucherModel voucherModel)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            //if (id != voucherModel.id)
            //{
            //    return BadRequest();
            //}

            //voucherService.UpdateVoucher(id, voucherModel);

            //return StatusCode(HttpStatusCode.NoContent);

            if (!ModelState.IsValid || voucherModel.offerId == null || voucherModel.userId == null)
            {
                return(BadRequest(ModelState));
            }

            if (id != voucherModel.id)
            {
                return(BadRequest());
            }

            OfferModel offer = offerService.GetOffer((int)voucherModel.offerId);
            UserModel  buyer = userService.GetUser((int)voucherModel.userId);

            if (offer == null || buyer == null)
            {
                return(NotFound());
            }

            if (buyer.user_role != UserModel.UserRoles.ROLE_CUSTOMER)
            {
                return(BadRequest("User's role must be ROLE_CUSTOMER"));
            }

            voucherModel.offerModel = offer;
            voucherModel.userModel  = buyer;
            VoucherModel updatedVoucher = voucherService.UpdateVoucher(id, voucherModel);

            if (updatedVoucher == null)
            {
                return(NotFound());
            }

            return(Ok(updatedVoucher));
        }