Example #1
0
        public ActionResult Generate(PromotionCouponsViewModel model)
        {
            var couponRecords = new List <UniqueCoupon>();

            for (var i = 0; i < model.Quantity; i++)
            {
                couponRecords.Add(new UniqueCoupon
                {
                    Code            = _couponService.GenerateCoupon(),
                    Created         = DateTime.UtcNow,
                    Expiration      = model.Expiration,
                    MaxRedemptions  = model.MaxRedemptions,
                    PromotionId     = model.PromotionId,
                    UsedRedemptions = 0,
                    Valid           = model.ValidFrom
                });
            }

            _couponService.SaveCoupons(couponRecords);
            return(RedirectToAction("EditPromotionCoupons", new { id = model.PromotionId }));
        }
Example #2
0
        public FileResult Download(PromotionCouponsViewModel model)
        {
            var coupons = _couponService.GetByPromotionId(model.PromotionId);

            var sb = new StringBuilder();

            //Headers

            sb.Append($"PromotionId,Code,ValidFrom,Expiration,CustomerId,MaxRedemptions,UsedRedemptions");
            sb.Append("\r\n");
            for (int i = 0; i < coupons.Count; i++)
            {
                sb.Append($"{coupons[i].PromotionId}," +
                          $"{coupons[i].Code}," +
                          $"{coupons[i].ValidFrom}," +
                          $"{coupons[i].Expiration}," +
                          $"{coupons[i].CustomerId}," +
                          $"{coupons[i].MaxRedemptions}," +
                          $"{coupons[i].UsedRedemptions}");
                sb.Append("\r\n");
            }

            return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/csv", $"{model.PromotionId}.csv"));
        }
Example #3
0
        public ActionResult DeleteAll(PromotionCouponsViewModel model)
        {
            var deleted = _couponService.DeleteByPromotionId(model.PromotionId);

            return(RedirectToAction("EditPromotionCoupons", new { id = model.PromotionId }));
        }