private bool InsertMultipleObjectFields(BaseDto objectToInsert) { foreach (var propertyInfo in objectToInsert.GetType().GetProperties().Where(c => c.GetCustomAttribute <RelativityObjectFieldAttribute>()?.FieldType == RdoFieldType.MultipleObject)) { var fieldGuid = propertyInfo.GetCustomAttribute <RelativityObjectFieldAttribute>()?.FieldGuid; if (fieldGuid == null) { continue; } IEnumerable <object> fieldValue = (IEnumerable <object>)objectToInsert.GetPropertyValue(propertyInfo.Name); if (fieldValue == null) { continue; } foreach (var childObject in fieldValue) { //TODO: better test to see if contains value...if all fields are null, not need if (((childObject as BaseDto).ArtifactId == 0)) { Type objType = childObject.GetType(); var newArtifactId = this.InvokeGenericMethod(objType, nameof(Insert), childObject); (childObject as BaseDto).ArtifactId = (int)newArtifactId; } else { //TODO: Consider update if fields have changed } } } return(true); }
private bool InsertSingleObjectFields(BaseDto objectToInsert) { foreach (var propertyInfo in objectToInsert.GetType().GetProperties()) { var attribute = propertyInfo.GetCustomAttribute <RelativityObjectFieldAttribute>(); if (attribute?.FieldType == RdoFieldType.SingleObject) { var fieldValue = (BaseDto)objectToInsert.GetPropertyValue(propertyInfo.Name); if (fieldValue != null) { Type objType = fieldValue.GetType(); var newArtifactId = this.InvokeGenericMethod(objType, nameof(Insert), fieldValue); fieldValue.ArtifactId = (int)newArtifactId; } } } return(true); }