public ImprovementProposal PostImprovementProposal([FromBody] Models.ImprovementProposal newProposal)
 {
     try
     {
         ImprovementProposal result = Services.Content.ImprovementProposal.CreateProposal(this._contentSettings, newProposal);
         return(result);
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 2
0
        public static Models.ImprovementProposal CreateProposal(ContentServiceConfiguration settings, Models.ImprovementProposal newProposal)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(settings.BaseUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.Add("api-version", "1.0");

                var stringContent = new StringContent(JsonConvert.SerializeObject(newProposal),
                                                      Encoding.UTF8,
                                                      "application/json");

                HttpResponseMessage response = client.PostAsync(settings.ResourceRoot + "/ImprovementProposals", stringContent).Result;
                if (response.IsSuccessStatusCode)
                {
                    string stringData = response.Content.ReadAsStringAsync().Result;
                    return(JsonConvert.DeserializeObject <Models.ImprovementProposal>(stringData));
                }
            }

            return(null);
        }