Beispiel #1
0
        /// <summary>
        /// Logic to save the edits made to a feature
        /// </summary>
        internal async Task <Feature> SaveEdits(PopupManager popupManager, FeatureTable table, ObservableCollection <DestinationRelationshipViewModel> destinationRelationships)
        {
            // feature that was edited
            var editedFeature = popupManager.Popup.GeoElement as ArcGISFeature;

            // verify that the PopupManager doesn't have any errors and prompt the user to fix errors before allowing them to save
            if (popupManager.HasValidationErrors())
            {
                UserPromptMessenger.Instance.RaiseMessageValueChanged(Properties.Resources.GetString("InvalidInput_Title"),
                                                                      Properties.Resources.GetString("InvalidInput_Message"),
                                                                      true);
                return(null);
            }

            try
            {
                // exit the PopupManager edit session
                await popupManager.FinishEditingAsync();

                // get relationship changes (if they exist) and relate them to the feature
                foreach (var destinationRelationship in destinationRelationships ?? new ObservableCollection <DestinationRelationshipViewModel>())
                {
                    if (destinationRelationship.PopupManager != null)
                    {
                        try
                        {
                            editedFeature.RelateFeature((ArcGISFeature)destinationRelationship.PopupManager.Popup.GeoElement, destinationRelationship.RelationshipInfo);
                        }
                        catch (Exception ex)
                        {
                            UserPromptMessenger.Instance.RaiseMessageValueChanged(null, ex.Message, true, ex.StackTrace);
                        }
                    }
                }

                // update feature
                await table.UpdateFeatureAsync(editedFeature);

                // apply edits to save the changes
                await editedFeature.FeatureTable.ApplyEdits();

                // refresh the attributes and geometry of the feature after saving
                // this will returna valid ObjectID
                editedFeature.Refresh();

                // re-select the feature (new features get unselected after the ObjectID is refreshed)
                if (editedFeature.Geometry != null)
                {
                    var featureLayer = table.FeatureLayer;
                    featureLayer.SelectFeature(editedFeature);
                }

                return(editedFeature);
            }
            catch (Exception ex)
            {
                UserPromptMessenger.Instance.RaiseMessageValueChanged(null, ex.Message, true, ex.StackTrace);
                return(null);
            }
        }