|
||
|
API examples for newer versions Please visit the latest API Examples documentation to view API examples for newer versions of Kentico. |
The following example creates a relationship name.
private bool CreateRelationshipName() { // Create new relationship name object RelationshipNameInfo newName = new RelationshipNameInfo();
// Set the properties newName.RelationshipDisplayName = "My new relationship name"; newName.RelationshipName = "MyNewRelationshipName";
// Save the relationship name RelationshipNameInfoProvider.SetRelationshipNameInfo(newName);
return true; } |
The following example gets and updates the relationship name created by the code example above.
private bool GetAndUpdateRelationshipName() { // Get the relationship name RelationshipNameInfo updateName = RelationshipNameInfoProvider.GetRelationshipNameInfo("MyNewRelationshipName"); if (updateName != null) { // Update the properties updateName.RelationshipDisplayName = updateName.RelationshipDisplayName.ToLower();
// Save the changes RelationshipNameInfoProvider.SetRelationshipNameInfo(updateName);
return true; }
return false; } |
The following example gets multiple relationship names based on a WHERE condition and bulk updates them.
private bool GetAndBulkUpdateRelationshipNames() { // Prepare the parameters string where = "RelationshipName LIKE N'MyNewRelationshipName%'";
// Get the data DataSet names = RelationshipNameInfoProvider.GetRelationshipNames(where, null); if (!DataHelper.DataSourceIsEmpty(names)) { // Loop through the individual items foreach (DataRow nameDr in names.Tables[0].Rows) { // Create object from DataRow RelationshipNameInfo modifyName = new RelationshipNameInfo(nameDr);
// Update the properties modifyName.RelationshipDisplayName = modifyName.RelationshipDisplayName.ToUpper();
// Save the changes RelationshipNameInfoProvider.SetRelationshipNameInfo(modifyName); }
return true; }
return false; } |
The following example adds the relationship name created by the first code example on this page to the current website.
private bool AddRelationshipNameToSite() { // Get the relationship name RelationshipNameInfo name = RelationshipNameInfoProvider.GetRelationshipNameInfo("MyNewRelationshipName"); if (name != null) { int nameId = name.RelationshipNameId; int siteId = CMSContext.CurrentSiteID;
// Save the binding RelationshipNameSiteInfoProvider.AddRelationshipNameToSite(nameId, siteId);
return true; }
return false; } |
The following example removes the relationship name added to the current website by the code example above from the website.
private bool RemoveRelationshipNameFromSite() { // Get the relationship name RelationshipNameInfo removeName = RelationshipNameInfoProvider.GetRelationshipNameInfo("MyNewRelationshipName"); if (removeName != null) { int siteId = CMSContext.CurrentSiteID;
// Get the binding RelationshipNameSiteInfo nameSite = RelationshipNameSiteInfoProvider.GetRelationshipNameSiteInfo(removeName.RelationshipNameId, siteId);
// Delete the binding RelationshipNameSiteInfoProvider.DeleteRelationshipNameSiteInfo(nameSite);
return true; }
return false; } |
The following example deletes the relationship name created by the first code example on this page.
private bool DeleteRelationshipName() { // Get the relationship name RelationshipNameInfo deleteName = RelationshipNameInfoProvider.GetRelationshipNameInfo("MyNewRelationshipName");
// Delete the relationship name RelationshipNameInfoProvider.DeleteRelationshipName(deleteName);
return (deleteName != null); } |