Skip to main content

Posts

Punk API 18hour Experiment - Step #5

        // PUT api/Ratings/         [HttpPost]         public void Post([FromBody] RatingDTO dto)         {             ///             /// Load the string to RatingDTO             /// To Query the List using the id             /// If Found update, if not Insert             ///             var row = data.Where(x => x.id == dto.beerid).FirstOrDefault();             if(row==null)             {                 BeerWithRatingsDTO temp = new BeerWithRatingsDTO();                 temp.comments.Add(new RatingShortDTO() { username = dto.username, userrating = dto.userrating, comment =...
Recent posts

Punk API 18hour Experiment - Step #4

To PUT update to the API????         public async Task<bool> SaveRating(BeerRatingDTO dto)         {             v ar response = await _client.PutAsJsonAsync<BeerRatingDTO> (AppSettings.WebApiBaseAddress + "BeerRatings", dto);             if (response.IsSuccessStatusCode)                 return true;             return false;         }

Punk API 18hour Experiment - Step #3

Test of Deserialization from FILE             string dataString = File.ReadAllText("data.json");             List<BeerDTO> dtoList = JsonConvert.DeserializeObject<List<BeerDTO>>(dataString);             string dataString2 = JsonConvert.SerializeObject(dtoList, Formatting.Indented);             txtResults.Text = dataString2;

Punk API 18hour Experiment - Step #2

Loading Json String into a List of objects, and save them to a File!             List<BeerDTO> dtoList = JsonConvert.DeserializeObject<List<BeerDTO>>(txtResults.Text);             string newString = JsonConvert.SerializeObject(dtoList, Formatting.Indented);             File.WriteAllText("data.json", newString);

Punk API 18hour Experiment - Step #1

Asynchronous Call using the HttpClient             var response = await client.GetAsync(txtURL.Text);             if (response.IsSuccessStatusCode)             {                 var responseContent = response.Content;                 string responseString = await responseContent.ReadAsStringAsync();                 //Console.WriteLine(responseString);                 txtResults.Text = responseString;             } Synchronous Call using the HttpClient             var response = client.GetAsync(txtURL.Text).Result;             if (response.IsSuccessStatusCode)             {         ...