public void GetRacesId() { Console.Clear(); Console.WriteLine("Enter Race ID"); int id = GetSafeInterger(); Console.Write("Connecting....."); Task <HttpResponseMessage> getTask = httpClient.GetAsync($"https://{aPIUrl}/api/Racing/{id}"); HttpResponseMessage response = getTask.Result; if (response.IsSuccessStatusCode) { Console.Clear(); var task = httpClient.GetAsync($"https://{aPIUrl}/api/Racing/{id}").Result; if (task.IsSuccessStatusCode) { RacingItem racing = task.Content.ReadAsAsync <RacingItem>().Result; Console.WriteLine($"Team Information: ID#{racing.Id}: {racing.TeamName}\nTeam Type: {racing.RaceEvent}\nLocation: {racing.BasedOutOF}\nDrivers: {racing.Drivers}\nCompany: {racing.Manufacturer.CompanyName}"); Console.WriteLine($"\n\n" + $"Manufacturer Information:\n\n" + $"Company Name: {racing.Manufacturer.CompanyName}\n" + $"Company Locations: {racing.Manufacturer.Locations}\n" + $"Founded: {racing.Manufacturer.Founded.ToShortDateString()}\n" + $"Company Id: {racing.Manufacturer.Id}"); } else { Console.WriteLine("Invalid ID"); } } AnyKey(); }
public void UpdateRaces() { Console.Clear(); Console.WriteLine("Enter Race ID to update"); int id = GetSafeInterger(); Console.Write("Connecting....."); Task <HttpResponseMessage> getTask = httpClient.GetAsync($"https://{aPIUrl}/api/Racing/{id}"); HttpResponseMessage response = getTask.Result; if (response.IsSuccessStatusCode) { Console.Clear(); var task = httpClient.GetAsync($"https://{aPIUrl}/api/Racing/{id}").Result; if (task.IsSuccessStatusCode) { RacingItem oldRacing = httpClient.GetAsync($"https://{aPIUrl}/api/Racing/{id}").Result.Content.ReadAsAsync <RacingItem>().Result; Console.WriteLine($" {oldRacing.ManufacturerID,-4} {oldRacing.TeamName} {oldRacing.BasedOutOF} {oldRacing.Drivers} {oldRacing.RaceEvent}"); Console.Clear(); Dictionary <string, string> newRace = new Dictionary <string, string>(); string Id = id.ToString(); newRace.Add("Id", Id); Console.Write("Manufacturer Id: "); newRace.Add("ManufacturerID", UpdateIntProperty(oldRacing.ManufacturerID.ToString())); Console.Write("Team Name: "); newRace.Add("TeamName", UpdateProperty(oldRacing.TeamName)); Console.Write("Based Out Of: "); newRace.Add("BasedOutOf", UpdateProperty(oldRacing.BasedOutOF)); Console.Write("Drivers: "); newRace.Add("Drivers", UpdateProperty(oldRacing.Drivers)); string raceType = GetRaceType(); newRace.Add("RaceEvent", raceType); Console.Clear(); Console.WriteLine("Sending..."); HttpContent newRaceHTTP = new FormUrlEncodedContent(newRace); Task <HttpResponseMessage> putResponse = httpClient.PutAsync($"https://{aPIUrl}/api/Racing/{id}", newRaceHTTP); if (putResponse.Result.IsSuccessStatusCode) { Console.WriteLine("Success"); } else { Console.WriteLine(putResponse.Result.StatusCode); Console.WriteLine("Failed to save or no changes made"); } } else { Console.WriteLine("Invalid ID"); } } AnyKey(); }