/// <summary> /// Sets attribute values that have been provided by a remote client. /// </summary> /// <remarks> /// This should be used to handle values the client sent back after /// calling the <see cref="GetClientEditableAttributeValues(IHasAttributes, Person, bool)"/> /// method. It handles conversion from custom data formats into the /// proper values to be stored in the database. /// </remarks> /// <param name="entity">The entity.</param> /// <param name="attributeValues">The attribute values.</param> /// <param name="currentPerson">The current person.</param> /// <param name="enforceSecurity">if set to <c>true</c> then security will be enforced.</param> public static void SetClientAttributeValues(this IHasAttributes entity, Dictionary <string, string> attributeValues, Person currentPerson, bool enforceSecurity = true) { if (entity == null || entity.Attributes == null || entity.AttributeValues == null) { return; } foreach (var kvp in attributeValues) { if (!entity.Attributes.ContainsKey(kvp.Key) || !entity.AttributeValues.ContainsKey(kvp.Key)) { continue; } var attribute = entity.Attributes[kvp.Key]; if (enforceSecurity && !attribute.IsAuthorized(Rock.Security.Authorization.EDIT, currentPerson)) { continue; } var value = ClientAttributeHelper.GetValueFromClient(attribute, kvp.Value); entity.SetAttributeValue(kvp.Key, value); } }
/// <summary> /// Sets a single attribute values that have been provided by a remote client. /// </summary> /// <remarks> /// This should be used to handle values the client sent back after /// calling the <see cref="GetClientEditableAttributeValues(IHasAttributes, Person, bool)"/> /// method. It handles conversion from custom data formats into the /// proper values to be stored in the database. /// </remarks> /// <param name="entity">The entity.</param> /// <param name="key">The attribute key to set.</param> /// <param name="value">The value provided by the remote client.</param> /// <param name="currentPerson">The current person.</param> /// <param name="enforceSecurity">if set to <c>true</c> then security will be enforced.</param> public static void SetClientAttributeValue(this IHasAttributes entity, string key, string value, Person currentPerson, bool enforceSecurity = true) { if (entity == null || entity.Attributes == null || entity.AttributeValues == null) { return; } if (!entity.Attributes.ContainsKey(key) || !entity.AttributeValues.ContainsKey(key)) { return; } var attribute = entity.Attributes[key]; if (enforceSecurity && !attribute.IsAuthorized(Rock.Security.Authorization.EDIT, currentPerson)) { return; } var databaseValue = ClientAttributeHelper.GetValueFromClient(attribute, value); entity.SetAttributeValue(key, databaseValue); }