public async Task AddNarrationAsync(NarrationCreation newNarration) { string url = $"{ HttpRepositorySettings.BaseApiUrl }/{ Controller }"; var request = new HttpRequestMessage(HttpMethod.Post, url); var content = JsonSerializer.Serialize <NarrationCreation>(newNarration, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); request.Content = new StringContent(content, Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); }
private async void btnSave_Click(object sender, RoutedEventArgs e) { Narration outNarration = new Narration(); if (!isNew) { outNarration = InNarration; } if (!isNew) { outNarration.NarrationID = InNarration.NarrationID; } outNarration.OrphanID = InOrphan.OrphanID; outNarration.EntryDate = dtEntryDate.Date.Value.DateTime; outNarration.Subject = txtSubject.Text; outNarration.Note = txtNarration.Text; // Make sure you validate the above stuff...blows up otherwise. if (isNew) { if (AppSettings.UseWebApi) { using (var client = new HttpClient()) { var narrationRepo = new NarrationHttpRepository(client); var newNarration = new NarrationCreation { OrphanID = outNarration.OrphanID, Subject = outNarration.Subject, Note = outNarration.Note, EntryDate = outNarration.EntryDate }; await narrationRepo.AddNarrationAsync(newNarration); } } else { // Update to Database NarrationDataService.AddNarration(outNarration); } } else { // Go get the one of interest, then overwrite. if (AppSettings.UseWebApi) { using (var client = new HttpClient()) { var narrationRepo = new NarrationHttpRepository(client); var narrationUpdate = new NarrationUpdate { OrphanID = outNarration.OrphanID, Subject = outNarration.Subject, Note = outNarration.Note, EntryDate = outNarration.EntryDate }; await narrationRepo.UpdateNarrationAsync(outNarration.NarrationID, narrationUpdate); } } else { // Update to Database NarrationDataService.SaveNarration(InOrphan.OrphanID, outNarration); } } // Close the page OrphanMasterDetailPage.contentNarration.Hide(); }