コード例 #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;

            if (!form.TryGetValue("electionId", out electionIdString) || !Guid.TryParse(electionIdString, out electionId))
            {
                throw new HttpException(HttpStatusCode.BadRequest, "Invalid request params");
            }

            var election = electroController.NominateCandidate(electionId, user);

            if (election == null)
            {
                throw new HttpException(HttpStatusCode.BadRequest, "Nominate FAILED");
            }

            WriteData(context, election.ToJson());

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