Пример #1
0
 public bool Add(VoucherAddView entity)
 {
     try
     {
         int count = 0;
         int max   = entity.LimitNumber;
         while (count < max)
         {
             Voucher voucher = new Voucher();
             voucher.AmountReduced  = entity.AmountReduced;
             voucher.IsApplyOrder   = entity.IsApplyOrder;
             voucher.IsUsed         = false;
             voucher.PercentReduced = entity.PercentReduced;
             voucher.Product        = entity.Product;
             voucher.Promotion      = entity.Promotion;
             voucher.Type           = entity.Type;
             voucher.Code           = $"{entity.PromotionCode}-{RandomUtils.RandomString(9, 9, true, true, false)}";
             if (!_voucher.CheckExistsCode(voucher.Code))
             {
                 if (_voucher.Add(voucher) != null)
                 {
                     _unitOfWork.Commit();
                     count += 1;
                 }
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }