public async Task <ActionResult> Create([FromBody] DemoDTO1 postData) { DemoDTO1 dd; try { using (var httpClient = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(postData), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync(_config.GetValue <string>("Service2Url"), content)) { string apiResponse = await response.Content.ReadAsStringAsync(); dd = JsonConvert.DeserializeObject <DemoDTO1>(apiResponse); } } return(Ok(dd)); } catch (Exception) { return(BadRequest()); throw; } }
public ActionResult Get() { try { DemoDTO1 dto; if (!memoryCache.TryGetValue <DemoDTO1>("data", out dto)) { dto = new DemoDTO1 { TotalSum = 1 }; memoryCache.Set <DemoDTO1>("data", dto, TimeSpan.FromDays(1)); } if (dto == null) { return(NotFound()); } return(Ok(dto)); } catch (Exception) { return(NotFound()); throw; } }
public ActionResult Create([FromBody] DemoDTO1 postData) { try { if (postData != null) { memoryCache.Set <DemoDTO1>("data", postData, TimeSpan.FromDays(1)); return(Ok(postData)); } else { return(BadRequest()); } } catch (Exception) { return(BadRequest()); throw; } }