string errorMessage = await QueuedTask.Run( () =>
{
//check for selected layer
if (MapView.Active.GetSelectedLayers().Count == 0)
return "Please select a source feature layer in the table of contents.";
//first get the feature layer that's selected in the table of contents
var srcFeatLyr = MapView.Active.GetSelectedLayers().OfType<FeatureLayer>().FirstOrDefault();
var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<ParcelLayer>().FirstOrDefault();
if (myParcelFabricLayer == null)
return "No parcel layer found in the map.";
try
{
var theActiveRecord = myParcelFabricLayer.GetActiveRecord();
if (theActiveRecord == null)
return "There is no Active Record. Please set the active record and try again.";
var editOper = new EditOperation()
{
Name = "Assign Features to Record",
ProgressMessage = "Assign Features to Record...",
ShowModalMessageAfterFailure = true,
SelectNewFeatures = true,
SelectModifiedFeatures = false
};
//add parcel type layers and their feature ids to a new Dictionary
var ids = new List<long>(srcFeatLyr.GetSelection().GetObjectIDs());
var sourceFeatures = new Dictionary<MapMember, List<long>>();
sourceFeatures.Add(srcFeatLyr, ids);
editOper.AssignFeaturesToRecord(myParcelFabricLayer,
SelectionSet.FromDictionary(sourceFeatures), theActiveRecord);
if (!editOper.Execute())
return editOper.ErrorMessage;
}
catch (Exception ex)
{
return ex.Message;
}
return "";
});
if (!string.IsNullOrEmpty(errorMessage))
MessageBox.Show(errorMessage, "Assign Features To Record.");