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 (EntityListPage) detail page (EntityDetailPage) is recreated.
            // Meaning that constructor is run and SelectedEntity is null.
            // If SuspendAndTerminate (e.g. debug mode) SelectedEntity is saved to SessionState (because of [RestorableState] attribute).
            // Therefore, if SelectedEntity has been saved, use it instead of doing GetEntityAsync.
            if (SelectedEntity == null) {
                string errorMessage = string.Empty;
                int entityId = (int)navigationParameter;

                if (entityId == 0) {
                    SelectedEntity = new Entity();
                    SelectedEntity.ValidateProperties();
                    RunAllCanExecute();
                }
                else {
                    try {
                        LoadingData = true;
                        CrudResult = await _entityRepository.GetEntityAsync(entityId);
                        SelectedEntity = JsonConvert.DeserializeObject<List<Entity>>(CrudResult.Content.ToString()).FirstOrDefault<Entity>();
                    }
                    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 OnNewEntity() {
     SelectedEntity = new Entity();
     SelectedEntity.ValidateProperties();
     RunAllCanExecute();
 }