Пример #1
0
        public JsonResult AjaxBatchSubmitCoupon()
        {
            UserAuthVM user = UserAuthHelper.GetCurrentUser();

            if (user == null)
            {
                throw new ECommerce.Utility.BusinessException();
            }
            string dataString = Request.Form["Data"];

            dataString = HttpUtility.UrlDecode(dataString);
            var CouponSysNos = ECommerce.Utility.SerializationUtility.JsonDeserialize2 <int[]>(dataString);

            {
                int    merchantSysNo = user.SellerSysNo;
                string userName      = user.UserID;
                if (CouponSysNos == null || CouponSysNos.Length < 1)
                {
                    throw new BusinessException(LanguageHelper.GetText("批量操作数据不能为空"));
                }
                StringBuilder sb           = new StringBuilder();
                int           errorCount   = 0;
                int           successCount = 0;
                foreach (int CouponSysNo in CouponSysNos)
                {
                    try
                    {
                        Coupon info = CouponService.Load(CouponSysNo);
                        if (merchantSysNo != info.MerchantSysNo)
                        {
                            throw new BusinessException(LanguageHelper.GetText("您没有权限操作该数据"));
                        }
                        if (info.Status != CouponStatus.Init)
                        {
                            throw new ECommerce.Utility.BusinessException(LanguageHelper.GetText("只有初始化状态的活动才能提交!"));
                        }
                        CouponService.CheckCoupon(info);
                        CouponService.UpdateStatus(CouponSysNo, CouponStatus.WaitingAudit, userName);
                        successCount++;
                    }
                    catch (BusinessException ex)
                    {
                        sb.AppendLine(string.Format(LanguageHelper.GetText("活动编号:{0} {1}<br/>"), CouponSysNo, ex.Message));
                        errorCount++;
                    }
                    catch (Exception ex)
                    {
                        sb.AppendLine(string.Format(LanguageHelper.GetText("活动编号:{0} {1}<br/>"), CouponSysNo, ex.Message));
                        errorCount++;
                    }
                }
                if (sb.Length > 0)
                {
                    StringBuilder exMessage = new StringBuilder();
                    exMessage.AppendLine(string.Format(LanguageHelper.GetText("操作已完成!成功{0}条,失败{1}条<br/>"), successCount, errorCount));
                    exMessage.AppendLine(sb.ToString());

                    throw new BusinessException(exMessage.ToString());
                }
            }
            return(Json(new { Data = true }));
        }