// Update an existing CommonDataType public async Task<CrudResult> UpdateStateAsync(State state) { using (HttpClientHandler handler = new HttpClientHandler { CookieContainer = new CookieContainer() }) { using (var httpClient = new HttpClient()) { string putUrl = string.Format("{0}{1}", _stateBaseUrl, state.Id.ToString()); var response = await httpClient.PutAsJsonAsync<State>(putUrl, state); await response.EnsureSuccessWithValidationSupportAsync(); CrudResult crudResult = await response.Content.ReadAsAsync<CrudResult>(); return crudResult; } } }
public async override void OnNavigatedTo(object navigationParameter, Windows.UI.Xaml.Navigation.NavigationMode navigationMode, Dictionary<string, object> viewModelState) { base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState); if (viewModelState != null) { if (navigationMode == NavigationMode.Refresh) { var stateErrorsCollection = RetrieveEntityStateValue<IDictionary<string, ReadOnlyCollection<string>>>("stateErrorsCollection", viewModelState); if (stateErrorsCollection != null) { SelectedState.SetAllErrors(stateErrorsCollection); } } } // Note: Each time app selects from main page (StateListPage) detail page (StateDetailPage) is recreated. // Meaning that constructor is run and SelectedState is null. // If SuspendAndTerminate (e.g. debug mode) SelectedState is saved to SessionState (because of [RestorableState] attribute). // Therefore, if SelectedState has been saved, use it instead of doing GetStateAsync. if (SelectedState == null) { string errorMessage = string.Empty; int stateId = (int)navigationParameter; if (stateId == 0) { SelectedState = new State(); SelectedState.ValidateProperties(); RunAllCanExecute(); } else { try { LoadingData = true; CrudResult = await _stateRepository.GetStateAsync(stateId); SelectedState = JsonConvert.DeserializeObject<List<State>>(CrudResult.Content.ToString()).FirstOrDefault<State>(); } 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 OnNewState() { SelectedState = new State(); SelectedState.ValidateProperties(); RunAllCanExecute(); }
private void OnNavCommand(State state) { _navService.Navigate("StateDetail", state.Id); }
// Update an existing State public async Task<CrudResult> UpdateStateAsync(State state) { CrudResult crudResult = await _stateServiceProxy.UpdateStateAsync(state); return crudResult; }