/// <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); } }
/// <summary> /// Updates the condition and DBH for the selected tree /// This is only used for the Update tree condition custom workflow /// </summary> internal static async Task UpdateIdentifiedFeature(ObservableCollection <OriginRelationshipViewModel> originRelatedRecords, Feature feature, PopupManager popupManager) { // if the webmap used in the app is not the tree dataset map, this method will not work if (WebmapURL != TreeDatasetWebmapUrl) { return; } // if there are no inspections available, reset condition and dbh and save feature if (originRelatedRecords.Count == 0) { feature.Attributes[TreeConditionAttribute] = ""; feature.Attributes[TreeDBHAttribute] = null; try { await feature.FeatureTable.UpdateFeature(feature); await feature.FeatureTable.ApplyEdits(); } catch (Exception ex) { UserPromptMessenger.Instance.RaiseMessageValueChanged( Resources.GetString("ConditionDBH_UpdateError_Title"), ex.Message, true, ex.StackTrace); } return; } var OrderedOriginRelationshipCollection = originRelatedRecords.OrderByDescending(x => x.PopupManager.DisplayedFields.First().Value); var lastInspection = OrderedOriginRelationshipCollection.First(); // if the condition and dbh are still the same, do not update feature if (lastInspection.PopupManager.DisplayedFields.Where(x => x.Field.FieldName == InspectionConditionAttribute) == popupManager.DisplayedFields.Where(x => x.Field.FieldName == TreeConditionAttribute) && lastInspection.PopupManager.DisplayedFields.Where(x => x.Field.FieldName == InspectionDBHAttribute) == popupManager.DisplayedFields.Where(x => x.Field.FieldName == TreeDBHAttribute)) { return; } else { // set the new atributes // set the condition to empty string if user left it blank // set the dbh to 0 if user left it blank feature.Attributes[TreeConditionAttribute] = lastInspection.PopupManager.DisplayedFields.Where(x => x.Field.FieldName == InspectionConditionAttribute).First().Value ?? ""; feature.Attributes[TreeDBHAttribute] = lastInspection.PopupManager.DisplayedFields.Where(x => x.Field.FieldName == InspectionDBHAttribute).First().Value ?? 0f; try { await feature.FeatureTable.UpdateFeature(feature); await feature.FeatureTable.ApplyEdits(); } catch (Exception ex) { UserPromptMessenger.Instance.RaiseMessageValueChanged( Resources.GetString("ConditionDBH_UpdateError_Title"), ex.Message, true, ex.StackTrace); } // HACK to refresh the popup manager when non editable fields are edited try { if (!popupManager.IsEditing) { popupManager.StartEditing(); } await popupManager.FinishEditingAsync(); } catch { popupManager.CancelEditing(); } } }