Example #1
0
        private void GetCouponToMember(System.Web.HttpContext context)
        {
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder("{");
            int couponId = 0;

            try
            {
                couponId = int.Parse(context.Request["couponId"]);
            }
            catch (System.Exception)
            {
                stringBuilder.Append("\"status\":\"0\",\"Desciption\":\"参数错误!\"}");
                context.Response.Write(stringBuilder.ToString());
                return;
            }
            int userId = 0;

            try
            {
                MemberInfo currentMember = MemberProcessor.GetCurrentMember();
                userId = currentMember.UserId;
            }
            catch (System.Exception)
            {
                userId = 1;
            }
            try
            {
                SendCouponResult sendCouponResult = CouponHelper.SendCouponToMember(couponId, userId);
                if (sendCouponResult == SendCouponResult.正常领取)
                {
                    stringBuilder.Append("\"status\":\"1\",\"Desciption\":\"领取成功!\"}");
                    context.Response.Write(stringBuilder.ToString());
                }
                else
                {
                    if (sendCouponResult == SendCouponResult.其它错误)
                    {
                        throw new System.Exception();
                    }
                    stringBuilder.Append("\"status\":\"2\",\"Desciption\":\"" + sendCouponResult.ToString() + "!\"}");
                    context.Response.Write(stringBuilder.ToString());
                }
            }
            catch (System.Exception)
            {
                stringBuilder.Append("\"status\":\"3\",\"Desciption\":\"领取失败!\"}");
                context.Response.Write(stringBuilder.ToString());
            }
        }
Example #2
0
        private void GetCouponToMember(HttpContext context)
        {
            StringBuilder builder  = new StringBuilder("{");
            int           couponId = 0;

            try
            {
                couponId = int.Parse(context.Request["couponId"]);
            }
            catch (Exception)
            {
                builder.Append("\"status\":\"0\",\"Desciption\":\"参数错误!\"}");
                context.Response.Write(builder.ToString());
                return;
            }
            int userId = 0;

            try
            {
                userId = MemberProcessor.GetCurrentMember().UserId;
            }
            catch (Exception)
            {
                userId = 1;
            }
            try
            {
                SendCouponResult result = CouponHelper.SendCouponToMember(couponId, userId);
                switch (result)
                {
                case SendCouponResult.正常领取:
                    builder.Append("\"status\":\"1\",\"Desciption\":\"领取成功!\"}");
                    context.Response.Write(builder.ToString());
                    return;

                case SendCouponResult.其它错误:
                    throw new Exception();
                }
                builder.Append("\"status\":\"2\",\"Desciption\":\"" + result.ToString() + "!\"}");
                context.Response.Write(builder.ToString());
            }
            catch (Exception)
            {
                builder.Append("\"status\":\"3\",\"Desciption\":\"领取失败!\"}");
                context.Response.Write(builder.ToString());
            }
        }