// Set the properties newModule.ResourceDisplayName = "My new module"; newModule.ResourceName = "MyNewModule";
// Save the module ResourceInfoProvider.SetResourceInfo(newModule);
returntrue; }
The following example gets and updates a module.
privatebool GetAndUpdateModule() { // Get the module ResourceInfo updateModule = ResourceInfoProvider.GetResourceInfo("MyNewModule"); if (updateModule != null) { // Update the properties updateModule.ResourceDisplayName = updateModule.ResourceDisplayName.ToLower();
// Save the changes ResourceInfoProvider.SetResourceInfo(updateModule);
returntrue; }
returnfalse; }
The following example gets and bulk updates modules.
privatebool GetAndBulkUpdateModules() { // Prepare the parameters string where = "ResourceName LIKE N'MyNewModule%'";
// Get the data DataSet modules = ResourceInfoProvider.GetResources(where, null); if (!DataHelper.DataSourceIsEmpty(modules)) { // Loop through the individual items foreach (DataRow moduleDr in modules.Tables[0].Rows) { // Create object from DataRow ResourceInfo modifyModule = newResourceInfo(moduleDr);
// Update the properties modifyModule.ResourceDisplayName = modifyModule.ResourceDisplayName.ToUpper();
// Save the changes ResourceInfoProvider.SetResourceInfo(modifyModule); }
returntrue; }
returnfalse; }
The following example adds a module to site.
privatebool AddModuleToSite() { /// Get the module ResourceInfo module = ResourceInfoProvider.GetResourceInfo("MyNewModule"); if (module != null) { int moduleId = module.ResourceId; int siteId = CMSContext.CurrentSiteID;
// Save the binding ResourceSiteInfoProvider.AddResourceToSite(moduleId, siteId);
returntrue; }
returnfalse; }
The following example gets and bulk updates site modules.
privatebool GetAndBulkUpdateSiteModules() { int siteId = CMSContext.CurrentSiteID; string where = "ResourceName LIKE N'MyNewModule%'";
// Get the data DataSet modules = ResourceInfoProvider.GetResources(where, null, 0, null, siteId); if (!DataHelper.DataSourceIsEmpty(modules)) { // Loop through the individual items foreach (DataRow moduleDr in modules.Tables[0].Rows) { // Create object from DataRow ResourceInfo modifyModule = newResourceInfo(moduleDr);
// Update the properties modifyModule.ResourceDisplayName = modifyModule.ResourceDisplayName.ToLower();
// Save the changes ResourceInfoProvider.SetResourceInfo(modifyModule); }
returntrue; }
returnfalse; }
The following example removes a module from site.
privatebool RemoveModuleFromSite() { // Get the module ResourceInfo removeModule = ResourceInfoProvider.GetResourceInfo("MyNewModule"); if (removeModule != null) { int siteId = CMSContext.CurrentSiteID;
// Get the binding ResourceSiteInfo moduleSite = ResourceSiteInfoProvider.GetResourceSiteInfo(removeModule.ResourceId, siteId);
// Delete the binding ResourceSiteInfoProvider.DeleteResourceSiteInfo(moduleSite);
returntrue; }
returnfalse; }
The following example deletes a module.
privatebool DeleteModule() { // Get the module ResourceInfo deleteModule = ResourceInfoProvider.GetResourceInfo("MyNewModule");
// Delete the module ResourceInfoProvider.DeleteResourceInfo(deleteModule);