public async System.Threading.Tasks.Task AddBook() { try { HttpClient client = new HttpClient(); AuthorPresentation selectedAuthor = (AuthorPresentation)cmbAuthor.SelectedItem; Author bookAuthor = new Author { Id = selectedAuthor.Id, FirstName = selectedAuthor.FirstName, LastName = selectedAuthor.LastName, Country = selectedAuthor.Country }; // ToDo: Glöm ej Country Book newBook = new Book(); newBook.Title = txtTitle.Text; newBook.Language = txtLanguage.Text; newBook.Genre = txtGenre.Text; newBook.Published = Int32.Parse(txtYear.Text); newBook.Authors = new List <Author>(); newBook.Authors.Add(bookAuthor); string jsonString = JsonConvert.SerializeObject(newBook); var content = new StringContent(jsonString, Encoding.UTF8, "application/json"); string URL = BASE_URL + "Books"; var response = await client.PostAsync(URL, content); var responseString = await response.Content.ReadAsStringAsync(); System.Diagnostics.Debug.WriteLine(responseString); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); var dialog = new MessageDialog("The connection to the database failed."); await dialog.ShowAsync(); } }
private List <AuthorPresentation> GetPresentationList(List <Author> authorList) { List <AuthorPresentation> returnList = new List <AuthorPresentation>(); foreach (var author in authorList) { AuthorPresentation presentationData = new AuthorPresentation { Id = author.Id, FirstName = author.FirstName, LastName = author.LastName }; returnList.Add(presentationData); } return(returnList); }