// Update an existing CommonDataType public async Task<CrudResult> UpdatePhoneCallAsync(PhoneCall phoneCall) { using (HttpClientHandler handler = new HttpClientHandler { CookieContainer = new CookieContainer() }) { using (var httpClient = new HttpClient()) { string putUrl = string.Format("{0}{1}", _phoneCallBaseUrl, phoneCall.Id.ToString()); var response = await httpClient.PutAsJsonAsync<PhoneCall>(putUrl, phoneCall); await response.EnsureSuccessWithValidationSupportAsync(); CrudResult crudResult = await response.Content.ReadAsAsync<CrudResult>(); return crudResult; } } }
public void HandlePhoneCallDeleted(PhoneCall phoneCall) { var threadId = Environment.CurrentManagedThreadId; var phoneCallId = phoneCall.Id; // Assign into local variable because it is meant to be fire and forget and calling would require an await/async var dialogAction = _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { MessageDialog dialog = new MessageDialog(string.Format(CultureInfo.InvariantCulture, "PhoneCall {0} deleted in background subscriber on thread {1}", phoneCallId, threadId)); var showAsync = dialog.ShowAsync(); }); }
public async override void OnNavigatedTo(object navigationParameter, Windows.UI.Xaml.Navigation.NavigationMode navigationMode, Dictionary<string, object> viewModelState) { base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState); // Note: Each time app selects from main page (PhoneCallListPage) detail page (PhoneCallDetailPage) is recreated. // Meaning that constructor is run and SelectedPhoneCall is null. // If SuspendAndTerminate (e.g. debug mode) SelectedPhoneCall is saved to SessionState (because of [RestorableState] attribute). // Therefore, if SelectedPhoneCall has been saved, use it instead of doing GetPhoneCallAsync. if (SelectedPhoneCall == null) { string errorMessage = string.Empty; int phoneCallId = (int)navigationParameter; if (phoneCallId == 0) { SelectedPhoneCall = new PhoneCall(); SelectedPhoneCall.ValidateProperties(); RunAllCanExecute(); } else { try { LoadingData = true; CrudResult = await _phoneCallRepository.GetPhoneCallAsync(phoneCallId); SelectedPhoneCall = JsonConvert.DeserializeObject<List<PhoneCall>>(CrudResult.Content.ToString()).FirstOrDefault<PhoneCall>(); } catch (HttpRequestException ex) { ErrorMessageTitle = ErrorMessagesHelper.HttpRequestExceptionError; //TODO: Log stack trace to database here ErrorMessage = string.Format("{0}", ex.Message); } finally { LoadingData = false; } if (ErrorMessage != null && ErrorMessage != string.Empty) { MessageDialog messageDialog = new MessageDialog(ErrorMessage, ErrorMessageTitle); await messageDialog.ShowAsync(); _navService.GoBack(); } } } RunAllCanExecute(); }
// When New button is pressed private void OnNewPhoneCall() { SelectedPhoneCall = new PhoneCall(); SelectedPhoneCall.ValidateProperties(); RunAllCanExecute(); }
private void OnNavCommand(PhoneCall phoneCall) { _navService.Navigate("PhoneCallDetail", phoneCall.Id); }
// Update an existing PhoneCall public async Task<CrudResult> UpdatePhoneCallAsync(PhoneCall phoneCall) { CrudResult crudResult = await _phoneCallServiceProxy.UpdatePhoneCallAsync(phoneCall); return crudResult; }