Ejemplo n.º 1
0
        public HttpResponseMessage Put()
        {
            var existingFormValues = GetSampleData().form;
            var newFormValues = Request.Content.ReadAsFormDataAsync().Result;
            bool foundKey = false;
            foreach (var key in newFormValues.AllKeys)
            {
                 if(existingFormValues.ContainsKey(key))
                 {
                     foundKey = true;
                     if (existingFormValues[key].ToString() != newFormValues[key])
                     {
                         existingFormValues[key] = newFormValues[key];
                     }
                     else
                     {
                         var response = Request.CreateResponse(HttpStatusCode.NotModified);
                         response.ReasonPhrase = "Resource not modified";
                         return response;
                     }
                 }
            }
               if(!foundKey)
               {
               return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Key not found");
               }

            var sampleData = new SampleData
                                 {
                                     url = Request.RequestUri.ToString(),
                                     headers = GetRequestHeaders(),
                                     origin = UserIpAddress,
                                     form = existingFormValues,
                                 };
            return Request.CreateResponse(HttpStatusCode.OK,
                                   sampleData);
        }
Ejemplo n.º 2
0
 public HttpResponseMessage Delete(string key)
 {
     var existingFormValues = GetSampleData().form;
     existingFormValues.Remove(key);
     var sampleData = new SampleData()
                         {
                             url = Request.RequestUri.ToString(),
                             headers = GetRequestHeaders(),
                             origin = UserIpAddress,
                             form = existingFormValues
                         };
     return Request.CreateResponse(HttpStatusCode.OK,
                            sampleData);
 }
Ejemplo n.º 3
0
 public HttpResponseMessage Post()
 {
     var existingFormValues = GetSampleData().form;
     var newFormValues = Request.Content.ReadAsFormDataAsync().Result;
     foreach (var key in newFormValues.AllKeys)
     {
        existingFormValues.Add(key, newFormValues[key]);
     }
     var sampleData = new SampleData
                          {
                              url = Request.RequestUri.ToString(),
                              headers = GetRequestHeaders(),
                              origin = UserIpAddress,
                              form = existingFormValues
                          };
     return Request.CreateResponse(HttpStatusCode.OK,
                            sampleData);
 }
Ejemplo n.º 4
0
 public static SampleData WithDefaults()
 {
     var d = new SampleData { form = new Dictionary<string, object>() { { "k0", "v0" } } };
     return d;
 }