private static void UpdateArtist() { Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Country: "); string country = Console.ReadLine(); Console.Write("Date of birth (yyyy-mm-dd): "); DateTime dateOfBirth = DateTime.ParseExact(Console.ReadLine(), "yyyy-mm-dd", CultureInfo.InvariantCulture); Artist updatedArtist = new Artist() { Name = name, Country = country, DateOfBirth = dateOfBirth }; Console.Write("Id to update: "); int idForUpdate = int.Parse(Console.ReadLine()); var putArtistResponse = jsonClient.PutAsJsonAsync("api/artists/" + idForUpdate, updatedArtist).Result; if (putArtistResponse.IsSuccessStatusCode) { Console.WriteLine("Artist updated!"); } else { Console.WriteLine("{0}, ({1})", (int)putArtistResponse.StatusCode, putArtistResponse.ReasonPhrase); } }
private static void CreateArtist() { Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Country: "); string country = Console.ReadLine(); Console.Write("Date of birth (yyyy-mm-dd): "); DateTime dateOfBirth = DateTime.ParseExact(Console.ReadLine(), "yyyy-mm-dd", CultureInfo.InvariantCulture); Artist artist = new Artist() { Name = name, Country = country, DateOfBirth = dateOfBirth }; var postArtistResponse = jsonClient.PostAsJsonAsync("api/artists", artist).Result; if (postArtistResponse.IsSuccessStatusCode) { Console.WriteLine("Artist added!"); } else { Console.WriteLine("{0} ({1})", (int)postArtistResponse.StatusCode, postArtistResponse.ReasonPhrase); } }