Beispiel #1
0
        public void ProcessRequest(HttpContext context)
        {
            string id          = context.Request["id"];
            string forceDelete = context.Request["force_delete"];

            //force_delete等于1时,则不管是否存在中奖记录,进行强制删除
            if (forceDelete != "1")
            {
                if (bllLottery.GetCountByKey <WXLotteryRecordV1>("LotteryId", id) > 0)
                {
                    resp.errcode = (int)APIErrCode.LotteryHaveRecord;
                    resp.errmsg  = string.Format("已经有人中奖,不能删除");
                    bllLottery.ContextResponse(context, resp);
                    return;
                }
            }
            BLLTransaction tran = new BLLTransaction();

            try
            {
                if (bllLottery.DeleteByKey <WXLotteryV1>("LotteryID", id, tran) == -1)
                {
                    tran.Rollback();
                    resp.errcode = (int)APIErrCode.OperateFail;
                    resp.errmsg  = "删除活动主表失败";
                    bllLottery.ContextResponse(context, resp);
                    return;
                }

                if (bllLottery.DeleteByKey <WXAwardsV1>("LotteryId", id, tran) == -1)
                {
                    tran.Rollback();
                    resp.errcode = (int)APIErrCode.OperateFail;
                    resp.errmsg  = "删除奖项失败";
                    bllLottery.ContextResponse(context, resp);
                    return;
                }
                if (bllLottery.DeleteByKey <WXLotteryRecordV1>("LotteryId", id, tran) == -1)
                {
                    tran.Rollback();
                    resp.errcode = (int)APIErrCode.OperateFail;
                    resp.errmsg  = "删除中奖记录失败";
                    bllLottery.ContextResponse(context, resp);
                    return;
                }
                if (bllLottery.DeleteByKey <WXLotteryLogV1>("LotteryId", id, tran) == -1)
                {
                    tran.Rollback();
                    resp.errcode = (int)APIErrCode.OperateFail;
                    resp.errmsg  = "删除抽奖记录失败";
                    bllLottery.ContextResponse(context, resp);
                    return;
                }
                if (bllLottery.DeleteByKey <WXLotteryWinningDataV1>("LotteryId", id, tran) == -1)
                {
                    tran.Rollback();
                    resp.errcode = (int)APIErrCode.OperateFail;
                    resp.errmsg  = "删除默认中奖设置失败";
                    bllLottery.ContextResponse(context, resp);
                    return;
                }
                tran.Commit();
                resp.isSuccess = true;
            }
            catch (Exception ex)
            {
                tran.Rollback();
                resp.errcode = (int)APIErrCode.OperateFail;
                resp.errmsg  = ex.Message;
            }
            bllLottery.ContextResponse(context, resp);
        }
Beispiel #2
0
        public void ProcessRequest(HttpContext context)
        {
            string lotteryId = context.Request["lottery_id"];
            string userId    = context.Request["user_id"];
            string awardId   = context.Request["award_id"];

            if (string.IsNullOrEmpty(lotteryId))
            {
                resp.errcode = (int)APIErrCode.IsNotFound;
                resp.errmsg  = "活动id为必填项,请检查";
                bllLottery.ContextResponse(context, resp);
                return;
            }
            if (string.IsNullOrEmpty(userId))
            {
                resp.errcode = (int)APIErrCode.IsNotFound;
                resp.errmsg  = "用户id为必填项,请检查";
                bllLottery.ContextResponse(context, resp);
                return;
            }
            if (string.IsNullOrEmpty(awardId))
            {
                resp.errcode = (int)APIErrCode.IsNotFound;
                resp.errmsg  = "奖项id为必填项,请检查";
                bllLottery.ContextResponse(context, resp);
                return;
            }
            if (bllUser.GetUserInfo(userId) == null)
            {
                resp.errcode = (int)APIErrCode.IsNotFound;
                resp.errmsg  = "用户名不存在,请检查";
                bllLottery.ContextResponse(context, resp);
                return;
            }
            if (bllLottery.ExistsWinningData(lotteryId, userId))
            {
                resp.errcode = (int)APIErrCode.IsRepeat;
                resp.errmsg  = "该用户名已经在中奖名单中";
                bllLottery.ContextResponse(context, resp);
                return;
            }
            int AwardCount = bllLottery.GetByKey <WXAwardsV1>("AutoID", awardId).PrizeCount;

            if (AwardCount - bllLottery.GetCountByKey <WXLotteryWinningDataV1>("WXAwardsId", awardId) - 1 < 0)
            {
                resp.errcode = (int)APIErrCode.OperateFail;
                resp.errmsg  = "默认中奖奖项之和超过了该奖项的数量";
                bllLottery.ContextResponse(context, resp);
                return;
            }

            WXLotteryWinningDataV1 model = new WXLotteryWinningDataV1();

            model.LotteryId  = Convert.ToInt32(lotteryId);
            model.UserId     = userId;
            model.WXAwardsId = Convert.ToInt32(awardId);
            if (bllLottery.Add(model))
            {
                resp.isSuccess = true;
                resp.errcode   = (int)APIErrCode.IsSuccess;
            }
            else
            {
                resp.errcode = (int)APIErrCode.OperateFail;
                resp.errmsg  = "添加失败";
            }
            bllLottery.ContextResponse(context, resp);
        }