string errorMessage = await QueuedTask.Run(async () =>
{
Dictionary<string, object> RecordAttributes = new Dictionary<string, object>();
string sNewRecord = "MyRecordName";
try
{
var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<ParcelLayer>().FirstOrDefault();
//if there is no fabric in the map then bail
if (myParcelFabricLayer == null)
return "There is no fabric in the map.";
var recordsLayer = await myParcelFabricLayer.GetRecordsLayerAsync();
var editOper = new EditOperation()
{
Name = "Create Parcel Fabric Record",
ProgressMessage = "Create Parcel Fabric Record...",
ShowModalMessageAfterFailure = true,
SelectNewFeatures = false,
SelectModifiedFeatures = false
};
RecordAttributes.Add("Name", sNewRecord);
var editRowToken = editOper.Create(recordsLayer.FirstOrDefault(), RecordAttributes);
if (!editOper.Execute())
return editOper.ErrorMessage;
var defOID = -1;
var lOid = editRowToken.ObjectID.HasValue ? editRowToken.ObjectID.Value : defOID;
await myParcelFabricLayer.SetActiveRecordAsync(lOid);
}
catch (Exception ex)
{
return ex.Message;
}
return "";
});
if (!string.IsNullOrEmpty(errorMessage))
MessageBox.Show(errorMessage, "Create New Record.");