Пример #1
0
        protected override void ProcessAuthorizedRequest(HttpListenerContext context, User user)
        {
            context.Request.AssertMethod(WebRequestMethods.Http.Post);
            var form = context.Request.GetPostData();

            string electionIdString; Guid electionId;
            string voteArrayString; string[] voteStringArray; BigInteger[] voteArray;

            if (!form.TryGetValue("electionId", out electionIdString) || !Guid.TryParse(electionIdString, out electionId) ||
                !form.TryGetValue("vote", out voteArrayString) || (voteStringArray = JsonHelper.TryParseJson <string[]>(voteArrayString)) == null || (voteArray = ParseVoteArray(voteStringArray)) == null)
            {
                throw new HttpException(HttpStatusCode.BadRequest, "Invalid request params");
            }

            var success = electroController.Vote(electionId, user, voteArray);

            if (!success)
            {
                throw new HttpException(HttpStatusCode.BadRequest, "Vote FAILED");
            }

            WriteString(context, "Vote OK");

            log.InfoFormat("Recorded user '{0}' vote in election '{1}'", user.Id, electionId);
        }