/// <summary> /// Event handler fires when the SelectedOriginRelationship is modified /// </summary> private async void OriginRelatedFeature_FeatureCRUDOperationCompleted(object sender, FeatureOperationEventArgs e) { var originRelationshipVM = sender as OriginRelationshipViewModel; var originRelationshipVMCollection = (OriginRelationships.FirstOrDefault(o => o.RelationshipInfo == originRelationshipVM.RelationshipInfo)).OriginRelationshipViewModelCollection; if (e.Args == CRUDOperation.Delete) { // remove viewmodel from collection originRelationshipVMCollection.Remove(originRelationshipVM); } else { //sort collection SortCollection(originRelationshipVMCollection); } try { // call method to update tree condition and dbh in custom tree workflow await TreeSurveyWorkflows.UpdateIdentifiedFeature(originRelationshipVMCollection, Feature, PopupManager); } catch (Exception ex) { UserPromptMessenger.Instance.RaiseMessageValueChanged( Resources.GetString("GenericError_Title"), ex.Message, true, ex.StackTrace); } }
/// <summary> /// Gets relationship information for the identified feature and creates the corresponding viewmodels /// </summary> internal async Task GetRelationshipInfoForFeature(ArcGISFeature feature) { // clear related records from previous searches DestinationRelationships.Clear(); OriginRelationships.Clear(); // get RelationshipInfos from the table var relationshipInfos = feature.FeatureTable.GetRelationshipInfos(); // query only the related tables which match the application rules // save destination and origin type relationships separately as origin relates features are editable in the app foreach (var relationshipInfo in relationshipInfos) { var parameters = new RelatedQueryParameters(relationshipInfo); // only one related table should return given the specific relationship info passed as parameter var relatedTable = feature.FeatureTable.GetRelatedFeatureTable(relationshipInfo); var relationships = await feature.FeatureTable.GetRelatedRecords(feature, relationshipInfo); if (relationshipInfo.IsValidDestinationRelationship()) { try { // this is a one to many relationship so it will never return more than one result var relatedFeatureQueryResult = relationships.Where(r => r.IsValidRelationship()).First(); var destinationRelationshipViewModel = new DestinationRelationshipViewModel(relationshipInfo, relatedTable, ConnectivityMode); await destinationRelationshipViewModel.InitializeAsync(relatedFeatureQueryResult); DestinationRelationships.Add(destinationRelationshipViewModel); } catch (Exception ex) { UserPromptMessenger.Instance.RaiseMessageValueChanged(null, Resources.GetString("QueryRelatedFeaturesError_Message"), true, ex.StackTrace); } } else if (relationshipInfo.IsValidOriginRelationship()) { try { foreach (var relatedFeatureQueryResult in relationships.Where(r => r.IsValidRelationship())) { var originRelationshipsCollection = new ObservableCollection <OriginRelationshipViewModel>(); foreach (var relatedFeature in relatedFeatureQueryResult) { var originRelatedFeature = new OriginRelationshipViewModel(relationshipInfo, ConnectivityMode); await originRelatedFeature.LoadViewModel(relatedFeature).ContinueWith(t => { originRelationshipsCollection.Add(originRelatedFeature); }); } //sort collection SortCollection(originRelationshipsCollection); OriginRelationships.Add(new OriginRelationship(relatedTable, relationshipInfo, originRelationshipsCollection)); } } catch (Exception ex) { UserPromptMessenger.Instance.RaiseMessageValueChanged(null, Resources.GetString("GetFeatureRelationshipError_Message"), true, ex.StackTrace); } } } }