private static async Task postUserAsync(UserJSON user) { var content = new StringContent(JsonSerializer.Serialize(new User(user)), Encoding.UTF8, "application/json"); var userPostResponse = await HttpClient.PostAsync("People", content); try { userPostResponse.EnsureSuccessStatusCode(); Console.WriteLine("User " + user.UserName + " created successfully"); } catch (Exception e) { Console.WriteLine("Creating user " + user.UserName + "did not work"); } }
public User(UserJSON user) { this.UserName = user.UserName; this.FirstName = user.FirstName; this.LastName = user.LastName; this.Emails = new List <string>() { user.Email }; this.AddressInfo = new List <AddressInfo>() { new AddressInfo(user.Address, new City(user.CityName, user.Country, "")) }; }