public TestorTreeItem[] AddGroups(int parentId, TestorTreeItem[] groups) { Debug.Assert(parentId >= 0); Provider.TestRoles(TestorUserRole.Administrator); using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString)) { foreach (TestorTreeItem group in groups) { int i = 1; string groupCode = String.Empty; while (i > 0) { groupCode = Guid.NewGuid().ToString().Substring(0, 8); i = dataContext.GetGroupIdByCode(groupCode); } group.GroupCode = groupCode; group.ItemId = dataContext.AddGroupTreeItem(GetId(parentId), group.ItemName, groupCode); AddGroups(group.ItemId, group.SubItems); } return(groups); } }