Beispiel #1
0
        private void UserVote(System.Web.HttpContext context)
        {
            context.Response.ContentType = "application/json";
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder("{");
            int voteId = 0;

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

            if (string.IsNullOrEmpty(text))
            {
                stringBuilder.Append("\"status\":\"0\",\"Desciption\":\"参数错误!\"}");
                context.Response.Write(stringBuilder.ToString());
            }
            else
            {
                try
                {
                    bool flag = VoteHelper.Vote(voteId, text);
                    if (!flag)
                    {
                        throw new System.Exception("投票失败!");
                    }
                    stringBuilder.Append("\"status\":\"1\",\"Desciption\":\"成功!\"}");
                    context.Response.Write(stringBuilder.ToString());
                }
                catch (System.Exception ex)
                {
                    stringBuilder.Append("\"status\":\"2\",\"Desciption\":\"" + ex.Message + "\"}");
                    context.Response.Write(stringBuilder.ToString());
                }
            }
        }
Beispiel #2
0
        private void UserVote(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            StringBuilder builder = new StringBuilder("{");
            int           voteId  = 0;

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

            if (!string.IsNullOrEmpty(str))
            {
                try
                {
                    if (!VoteHelper.Vote(voteId, str))
                    {
                        throw new Exception("投票失败!");
                    }
                    builder.Append("\"status\":\"1\",\"Desciption\":\"成功!\"}");
                    context.Response.Write(builder.ToString());
                }
                catch (Exception exception)
                {
                    builder.Append("\"status\":\"2\",\"Desciption\":\"" + exception.Message + "\"}");
                    context.Response.Write(builder.ToString());
                }
            }
            else
            {
                builder.Append("\"status\":\"0\",\"Desciption\":\"参数错误!\"}");
                context.Response.Write(builder.ToString());
            }
        }