public async Task <ActionResult <Model> > FeedModel() { var flats = getOffersToFeedModel(); if (flats.Count < 1) { return(NoContent()); } var request = new FeedModelRequest(mapper.Map <List <FlatToModelDTO> >(flats)); var httpContent = getStringContentFromFeedModelRequest(request); HttpResponseMessage response = await client.PostAsync("/update_model/", httpContent); if (response.IsSuccessStatusCode) { var responseString = await response.Content.ReadAsStringAsync(); var responseModel = JsonConvert.DeserializeObject <Model>(responseString); var model = modelRepository.SaveModel(responseModel, request.Samples.Count); var isUpdated = updateFlatsUsedInModel(flats); return(model); } else { return(null); } }
private StringContent getStringContentFromFeedModelRequest(FeedModelRequest request) { var serializerSettings = new JsonSerializerSettings(); serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); string json = JsonConvert.SerializeObject(request, serializerSettings); return(new StringContent(json, System.Text.Encoding.UTF8, "application/json")); }