protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         int         photoId    = int.Parse(Request["photoId"]);
         VotesHelper voteObject = new VotesHelper();
         voteObject.DoVote(Context, photoId);
     }
     catch (NullReferenceException nre) {
         System.Diagnostics.Debug.WriteLine("An error occurred: There was a request for a " +
                                            "photo that is not in the datastore." + nre.StackTrace);
     }
     catch (ArgumentNullException ane) {
         System.Diagnostics.Debug.WriteLine("An error occurred: There was a request for a " +
                                            "photo that is not in the datastore." + ane.StackTrace);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// The route handler for the request, increments vote counts.
        /// </summary>
        /// <param name="context">The request and response context.</param>
        public override void ProcessRequest(HttpContext context)
        {
            Photo       voteTarget  = null;
            VotesHelper votesHelper = new VotesHelper();

            if (context.Request.RequestType.Equals("PUT"))
            {
                StreamReader stream       = new StreamReader(context.Request.InputStream);
                string       voteJson     = stream.ReadToEnd();
                PhotoRequest photoRequest = (PhotoRequest) new PhotoRequest().FromJson(voteJson);
                voteTarget = votesHelper.DoVote(context, photoRequest.photoId);
            }

            if (voteTarget == null)
            {
                SendError(context.Response, 401, "Unauthorized request.");
            }
            else
            {
                SendResponse(context, voteTarget);
            }
        }