public HttpResponseMessage CalculateSalaryRaise(HttpRequestMessage request) { try { InternalPhysician physicianBase = request.Content.ReadAsAsync <InternalPhysician>().Result; physicianBase.Salary = physicianBase.CalculateSalaryRaise(); return(Request.CreateResponse(HttpStatusCode.OK, physicianBase, new MediaTypeHeaderValue("text/json"))); } catch (Exception exception) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception)); } }
/// <summary> /// Process Raise Salary request object /// <param name="address">Request Uri value</param> /// </summary> /// <param name="response">Awaitable task object</param> private static async Task ProcessRaiseSalaryRequest(Uri address) { using (HttpClient httpClient = new HttpClient()) { HttpRequestMessage request = new HttpRequestMessage(); request.Method = HttpMethod.Post; // HttpMethod.Put is also works request.RequestUri = address; PhysicianBase physician = new InternalPhysician() { FirstName = "Joe", LastName = "Doe", Salary = 120000 }; string requestobject = JsonConvert.SerializeObject(physician, Formatting.Indented); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Before Salary raised \n{0}", requestobject); request.Content = new ObjectContent(typeof(PhysicianBase), physician, new JsonMediaTypeFormatter(), new MediaTypeHeaderValue("text/json")); await httpClient.SendAsync(request). ContinueWith((response) => { try { ProcessRaiseSalaryResponse(response); } catch (AggregateException aggregateException) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(string.Format("Exception {0}", aggregateException)); } }); } }
public HttpResponseMessage AddInternalPhysician(HttpRequestMessage physicianRequest) { InternalPhysician internalPhysician = physicianRequest.Content.ReadAsAsync <InternalPhysician>().Result; return(base.AddPhysician(internalPhysician)); }