Beispiel #1
0
        public async Task <ActionResult> Create(CreateRewardRedemptionModel model)
        {
            if (ModelState.IsValid)
            {
                model.CreatedBy   = CurrentUser.UserId;
                model.CreatedDate = DateTime.Now;

                var response = await WepApiMethod.SendApiAsync <CreateRewardRedemptionModel>
                                   (HttpVerbs.Post, $"Reward/RewardRedemption", model);

                if (response.isSuccess)
                {
                    await LogActivity(Modules.Setting, "Create Reward Redemption Settings");

                    TempData["SuccessMessage"] = "Reward Redemption Settings created successfully";
                    return(RedirectToAction("List"));
                }
                else
                {
                    ErrorMsgReceived msg = JsonConvert.DeserializeObject <ErrorMsgReceived>(response.ErrorMessage);
                    TempData["ErrorMessage"] = "Failed to create Reward Redemption Settings : " + msg.Message;
                    return(RedirectToAction("List"));
                }
            }
            else
            {
                TempData["ErrorMessage"] = "Failed to create Reward Redemption Settings";
                return(RedirectToAction("List"));
            }
        }
        // POST: api/RewardRedemption
        public IHttpActionResult Post(CreateRewardRedemptionModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            //check if code already exist
            var rwd = db.RewardRedemption.Where(r => r.RewardCode == model.RewardCode).FirstOrDefault();

            if (rwd != null)
            {
                return(BadRequest("Reward Code already exist. Please use another code"));
            }

            var rewardRedemption = new RewardRedemption
            {
                RewardCode     = model.RewardCode,
                Description    = model.Description,
                DiscountValue  = model.DiscountValue,
                PointsToRedeem = model.PointsToRedeem,
                ValidDuration  = model.ValidDuration,
                CreatedBy      = model.CreatedBy.Value,
                CreatedDate    = DateTime.Now,
                Display        = true
            };

            db.RewardRedemption.Add(rewardRedemption);
            db.SaveChanges();

            return(Ok(rewardRedemption));
        }
Beispiel #3
0
        // GET: Reward/RewardRedemptions/Create
        public ActionResult Create()
        {
            CreateRewardRedemptionModel model = new CreateRewardRedemptionModel();

            model.CreatedBy = CurrentUser.UserId;

            return(View(model));
        }