public JsonResult PostSqrt([FromBody] SqrtOperand sqrtOperand) { SqrtResult result = new SqrtResult(); string trackingId = Request.Headers[MyStaticData.HEADER_TRACKING_ID]; result = sqrtService.Operate(sqrtOperand); if (trackingId != string.Empty) { Operation operation = new Operation("Sqrt", string.Join("sqrt", sqrtOperand.Number) + " = " + result.Square, DateTime.Now); User user = new User(new TrackingId(trackingId), operation); operationService.SaveOperations(user); } return(Json(result)); }
private static async void SquareRoot() { string url = BASE_URL + "sqrt"; SqrtOperand sqrtOperand = new SqrtOperand(); HttpContent content; HttpResponseMessage response = new HttpResponseMessage(); Console.WriteLine(MyStaticData.READ_NUMBER_FROM_KEYBOARD); sqrtOperand.Number = ReadNumber.Read(); string json = JsonConvert.SerializeObject(sqrtOperand); content = new StringContent(json, Encoding.UTF8, MyStaticData.MIME_TYPE_JSON); response = await client.PostAsync(url, content); Stream responseStream = await response.Content.ReadAsStreamAsync(); string streamContent = new StreamReader(responseStream).ReadToEnd(); SqrtResult resultJson = JsonConvert.DeserializeObject <SqrtResult>(streamContent); Console.WriteLine(resultJson.ToString()); }