// Update an existing CommonDataType
 public async Task<CrudResult> UpdatePersonAsync(Person person) {
     using (HttpClientHandler handler = new HttpClientHandler { CookieContainer = new CookieContainer() }) {
         using (var httpClient = new HttpClient()) {
             string putUrl = string.Format("{0}{1}", _personBaseUrl, person.Id.ToString());
             var response = await httpClient.PutAsJsonAsync<Person>(putUrl, person);
             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 personErrorsCollection = RetrieveEntityStateValue<IDictionary<string, ReadOnlyCollection<string>>>("personErrorsCollection", viewModelState);
                    if (personErrorsCollection != null) {
                        SelectedPerson.SetAllErrors(personErrorsCollection);
                    }
                }
            }

            // Note: Each time app selects from main page (PersonListPage) detail page (PersonDetailPage) is recreated.
            // Meaning that constructor is run and SelectedPerson is null.
            // If SuspendAndTerminate (e.g. debug mode) SelectedPerson is saved to SessionState (because of [RestorableState] attribute).
            // Therefore, if SelectedPerson has been saved, use it instead of doing GetPersonAsync.
            if (SelectedPerson == null) {
                string errorMessage = string.Empty;
                int personId = (int)navigationParameter;

                if (personId == 0) {
                    SelectedPerson = new Person();
                    SelectedPerson.ValidateProperties();
                    RunAllCanExecute();
                }
                else {
                    try {
                        LoadingData = true;
                        CrudResult = await _personRepository.GetPersonAsync(personId);
                        SelectedPerson = JsonConvert.DeserializeObject<List<Person>>(CrudResult.Content.ToString()).FirstOrDefault<Person>();
                    }
                    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 OnNewPerson() {
     SelectedPerson = new Person();
     SelectedPerson.ValidateProperties();
     RunAllCanExecute();
 }
 // Update an existing Person
 public async Task<CrudResult> UpdatePersonAsync(Person person) {
     CrudResult crudResult = await _personServiceProxy.UpdatePersonAsync(person);
     return crudResult;
 }
 private void OnNavCommand(Person person) {
     _navService.Navigate("PersonDetail", person.Id);
 }