/// <summary> /// Returns safe and unique codename for specified display name. /// </summary> private string GetUniqueCodeName(string codeName) { const int maxLength = 89; codeName = SqlHelper.GetSafeQueryString(codeName, false); string originalCodename = codeName; int postfixValue = 1; // Loop until unique code name is not found while (true) { string where = "(GroupName = N'" + codeName + "'"; if (mSiteId > 0) { where += " AND GroupSiteID = " + mSiteId; } where += ")"; DataSet ds = GroupInfoProvider.GetGroups(where, null, 0, "groupid"); // Default codename is unique if (DataHelper.DataSourceIsEmpty(ds)) { return(codeName); } codeName = GenerateCodeName(originalCodename, maxLength, "_" + postfixValue); postfixValue++; } }
/// <summary> /// Gets and bulk updates groups. Called when the "Get and bulk update groups" button is pressed. /// Expects the CreateGroup method to be run first. /// </summary> private bool GetAndBulkUpdateGroups() { // Prepare the parameters string where = "GroupName LIKE N'MyNewGroup%'"; // Get the data DataSet groups = GroupInfoProvider.GetGroups(where, null); if (!DataHelper.DataSourceIsEmpty(groups)) { // Loop through the individual items foreach (DataRow groupDr in groups.Tables[0].Rows) { // Create object from DataRow GroupInfo modifyGroup = new GroupInfo(groupDr); // Update the properties modifyGroup.GroupDisplayName = modifyGroup.GroupDisplayName.ToUpper(); // Save the changes GroupInfoProvider.SetGroupInfo(modifyGroup); } return(true); } return(false); }
/// <summary> /// Checks whether the given code name is unique. /// </summary> private bool CodeNameIsUnique(string codeName, int currentGroupId) { string where = "GroupName = N'" + SqlHelperClass.GetSafeQueryString(codeName, false) + "'"; // Filter out current group if (currentGroupId > 0) { where = SqlHelperClass.AddWhereCondition(where, "GroupID <> " + currentGroupId); } if (this.SiteID > 0) { where = SqlHelperClass.AddWhereCondition(where, "GroupSiteID = " + this.SiteID); } return(DataHelper.DataSourceIsEmpty(GroupInfoProvider.GetGroups(where, null))); }