コード例 #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);
     }
 }
コード例 #2
0
 public ActionResult Add(VoucherAddView model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (_voucherBusiness.Add(model))
             {
                 return(Redirect($"/Promotion/Detail/{model.Promotion}"));
             }
         }
         return(View());
     }
     catch (Exception)
     {
         return(View());
     }
 }
コード例 #3
0
        public ActionResult Add(long id)
        {
            try
            {
                HttpCookie          reqCookies = Request.Cookies["VendorLoginCookie"];
                ResponseVendorLogin login      = JsonConvert.DeserializeObject <ResponseVendorLogin>(reqCookies.Value.ToString().UrlDecode());
                if (login == null)
                {
                    return(Redirect("/System/Login"));
                }

                var products  = _productBusiness.GetAll(login.ID);
                var promotion = _promotionBusiness.GetByID(id);

                VoucherAddView view = new VoucherAddView();
                view.Promotion     = id;
                view.Vendor        = login.ID;
                view.PromotionCode = promotion.Code;
                if (!promotion.Type.Contains("1"))
                {
                    view.LimitNumber = 1;
                }
                else
                {
                    view.LimitNumber = promotion.Limit;
                }

                ViewBag.ProductList = products;

                return(View(view));
            }
            catch (Exception)
            {
                return(Redirect("/Product/List"));
            }
        }