本文整理汇总了C#中Group.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Group.Save方法的具体用法?C# Group.Save怎么用?C# Group.Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Group
的用法示例。
在下文中一共展示了Group.Save方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnCreateGroup_Click
//.........这里部分代码省略.........
List<int> lCategoriesIDs = new List<int>();
foreach (ListItem item in lbCategories.Items)
{
if (item.Selected)
{
lCategoriesIDs.Add(Convert.ToInt32(item.Value));
}
}
if (lCategoriesIDs.Count == 0)
{
lblError.Text = Lang.Trans("Please select category.");
return;
}
#endregion
#region Validate Description
if (description.Length == 0)
{
lblError.Text = Lang.Trans("Please enter group description.");
return;
}
#endregion
#region Validate Group Icon
Image image = null;
if (fuGroupImage.PostedFile.FileName.Length == 0)
{
image = Image.FromFile(Server.MapPath("~/Images") + "/defaultgroupicon.jpg");
}
else
{
try
{
image = Image.FromStream
(fuGroupImage.PostedFile.InputStream);
}
catch
{
lblError.Text = Lang.Trans("Invalid image!");
return;
}
}
#endregion
#endregion
if (Group.IsNameUsed(name))
{
StatusPageMessage = Lang.Trans("Group with such name already exists!");
Response.Redirect("~/ShowStatus.aspx");
}
Group group = new Group();
group.JoinTerms = terms;
group.Name = name;
group.Description = description;
if (ddAgeRestriction.SelectedValue != "-1") group.MinAge = Convert.ToInt32(ddAgeRestriction.SelectedValue);
if (CurrentUserSession != null && CurrentUserSession.IsAdmin() || Config.Groups.AutoApproveGroups)
{
group.Approved = true;
}
if (cbAutomaticallyJoin.Checked)
{
group.Autojoin = true;
group.AutojoinCountry = dropCountry.SelectedValue.Trim() != String.Empty ? dropCountry.SelectedValue.Trim() : null;
group.AutojoinRegion = dropRegion.SelectedValue.Trim() != String.Empty ? dropRegion.SelectedValue.Trim() : null;
group.AutojoinCity = dropCity.SelectedValue.Trim() != String.Empty ? dropCity.SelectedValue.Trim() : null;
}
group.AccessLevel = accessLevel;
group.Owner = owner;
if (accessLevel == Group.eAccessLevel.Moderated)
group.JoinQuestion = question;
group.ActiveMembers++;
group.Save();
group.SetCategories(lCategoriesIDs.ToArray());
Group.SaveIcon(group.ID, image);
GroupMember groupMember = new GroupMember(group.ID, CurrentUserSession.Username);
groupMember.Active = true;
groupMember.Type = GroupMember.eType.Admin;
groupMember.Save();
StatusPageMessage = Lang.Trans("Your group has been created successfully!");
Response.Redirect("~/ShowStatus.aspx");
}
示例2: Group_Creation
public void Group_Creation()
{
string testGroupAName = "TestGroupA";
string testGroupAPath = RepositoryPath.Combine(Repository.Root.Path, testGroupAName);
if (Node.Exists(testGroupAPath))
Node.ForceDelete(testGroupAPath);
string testGroupBName = "TestGroupB";
string testGroupBPath = RepositoryPath.Combine(Repository.Root.Path, testGroupBName);
if (Node.Exists(testGroupBPath))
Node.ForceDelete(testGroupBPath);
string testGroupCName = "TestGroupC";
string testGroupCPath = RepositoryPath.Combine(Repository.Root.Path, testGroupCName);
if (Node.Exists(testGroupCPath))
Node.ForceDelete(testGroupCPath);
string testUserAName = "TestUserA";
string testUserAPath = RepositoryPath.Combine("/Root/IMS/BuiltIn/Portal", testUserAName);
if (Node.Exists(testUserAPath))
Node.ForceDelete(testUserAPath);
User testUserA = new User(Node.LoadNode("/Root/IMS/BuiltIn/Portal"));
testUserA.Name = testUserAName;
testUserA.Save();
AddPathToDelete(testGroupAPath);
AddPathToDelete(testGroupBPath);
AddPathToDelete(testGroupCPath);
AddPathToDelete(testUserAPath);
Group testGroupA = new Group(Repository.Root);
testGroupA.Name = testGroupAName;
testGroupA.AddMember(User.Administrator);
testGroupA.AddMember(User.Visitor);
testGroupA.Save();
Group testGroupB = new Group(Repository.Root);
testGroupB.Name = testGroupBName;
testGroupB.AddMember(User.Administrator);
testGroupB.AddMember(testGroupA);
testGroupB.Save();
Group testGroupC = new Group(Repository.Root);
testGroupC.Name = testGroupCName;
testGroupC.AddMember(testGroupB);
testGroupC.Save();
//testGroupA.AddMember(testGroupC);
//testGroupA.Save();
}
示例3: Group_Bug740_Circular
public void Group_Bug740_Circular()
{
var domainNode = Node.LoadNode("/Root/IMS/BuiltIn");
var groups = new Group[5];
for (int i = 0; i < groups.Length; i++)
{
var name = "G_Bug740_" + i;
var path = "/Root/IMS/BuiltIn/" + name;
var group = Node.Load<Group>(path);
if (group == null)
{
group = new Group(domainNode);
group.Name = name;
group.Save();
AddPathToDelete(path);
groups[i] = group;
}
}
var group0 = Node.Load<Group>(groups[0].Id);
var group1 = Node.Load<Group>(groups[1].Id);
var group2 = Node.Load<Group>(groups[2].Id);
var group3 = Node.Load<Group>(groups[3].Id);
var group4 = Node.Load<Group>(groups[4].Id);
group0.AddMember(group1);
group0.AddMember(group2);
group1.AddMember(group2);
group2.AddMember(group3);
group3.AddMember(group4);
//-- add circular ref
try
{
group4.AddMember(group0);
}
catch (InvalidOperationException)
{
//-- ok
}
}
示例4: Group_AddSelf
public void Group_AddSelf()
{
Group group;
var domainNode = Node.LoadNode("/Root/IMS/BuiltIn");
var name = "G_AddSelf";
var path = "/Root/IMS/BuiltIn/" + name;
group = Node.Load<Group>(path);
if (group == null)
{
group = new Group(domainNode);
group.Name = name;
group.Save();
AddPathToDelete(path);
}
group = Node.Load<Group>(group.Id);
group.AddMember(group);
}
示例5: Group_Bug1882_MixedMembership
public void Group_Bug1882_MixedMembership()
{
Group group;
User user;
var domainNode = Node.LoadNode("/Root/IMS/BuiltIn");
var testFolder = Node.LoadNode("/Root/TestFolder_Bug1882");
if (testFolder == null)
{
testFolder = new Folder(Repository.Root);
testFolder.Name = "TestFolder_Bug1882";
testFolder.Save();
AddPathToDelete("/Root/TestFolder_Bug1882");
}
group = Node.Load<Group>("/Root/IMS/BuiltIn/G1");
if (group == null)
{
group = new Group(domainNode);
group.Name = "G1";
group.Save();
AddPathToDelete("/Root/IMS/BuiltIn/G1");
}
testFolder.Security.SetPermission(group, true, PermissionType.AddNew, PermissionValue.Allow);
group = Node.Load<Group>("/Root/IMS/BuiltIn/G2");
if (group == null)
{
group = new Group(domainNode);
group.Name = "G2";
group.Save();
AddPathToDelete("/Root/IMS/BuiltIn/G2");
}
testFolder.Security.SetPermission(group, true, PermissionType.Approve, PermissionValue.Allow);
user = Node.Load<User>("/Root/IMS/BuiltIn/U1");
if (user == null)
{
user = new User(domainNode);
user.Name = "U1";
user.Save();
AddPathToDelete("/Root/IMS/BuiltIn/U1");
}
Assert.IsFalse(testFolder.Security.HasPermission((IUser)user, PermissionType.AddNew), "#1");
Assert.IsFalse(testFolder.Security.HasPermission((IUser)user, PermissionType.Approve), "#2");
user = Node.Load<User>("/Root/IMS/BuiltIn/U2");
if (user == null)
{
user = new User(domainNode);
user.Name = "U2";
user.Save();
AddPathToDelete("/Root/IMS/BuiltIn/U2");
}
Assert.IsFalse(testFolder.Security.HasPermission((IUser)user, PermissionType.AddNew), "#3");
Assert.IsFalse(testFolder.Security.HasPermission((IUser)user, PermissionType.Approve), "#4");
//--
var group1 = Node.Load<Group>("/Root/IMS/BuiltIn/G1");
var group2 = Node.Load<Group>("/Root/IMS/BuiltIn/G2");
var user1 = Node.Load<User>("/Root/IMS/BuiltIn/U1");
var user2 = Node.Load<User>("/Root/IMS/BuiltIn/U2");
group1.AddMember(user1);
group1.Save();
Assert.IsTrue(testFolder.Security.HasPermission((IUser)user1, PermissionType.AddNew), "#5");
Assert.IsFalse(testFolder.Security.HasPermission((IUser)user1, PermissionType.Approve), "#6");
Assert.IsFalse(testFolder.Security.HasPermission((IUser)user2, PermissionType.AddNew), "#7");
Assert.IsFalse(testFolder.Security.HasPermission((IUser)user2, PermissionType.Approve), "#8");
group2.AddMember(user2);
group2.Save();
Assert.IsTrue(testFolder.Security.HasPermission((IUser)user1, PermissionType.AddNew), "#9");
Assert.IsFalse(testFolder.Security.HasPermission((IUser)user1, PermissionType.Approve), "#10");
Assert.IsFalse(testFolder.Security.HasPermission((IUser)user2, PermissionType.AddNew), "#11");
Assert.IsTrue(testFolder.Security.HasPermission((IUser)user2, PermissionType.Approve), "#12");
group1 = Node.Load<Group>("/Root/IMS/BuiltIn/G1");
group1.AddMember(Node.Load<Group>("/Root/IMS/BuiltIn/G2"));
group1.Save();
Assert.IsTrue(testFolder.Security.HasPermission((IUser)user1, PermissionType.AddNew), "#13");
Assert.IsFalse(testFolder.Security.HasPermission((IUser)user1, PermissionType.Approve), "#14");
Assert.IsTrue(testFolder.Security.HasPermission((IUser)user2, PermissionType.AddNew), "#15");
Assert.IsTrue(testFolder.Security.HasPermission((IUser)user2, PermissionType.Approve), "#16");
//--
group = Node.Load<Group>("/Root/IMS/BuiltIn/G3");
if (group == null)
{
group = new Group(domainNode);
group.Name = "G3";
group.Save();
AddPathToDelete("/Root/IMS/BuiltIn/G3");
}
//.........这里部分代码省略.........
示例6: SaveGroup
public static Group SaveGroup(Group group)
{
group.Save();
return group;
}
示例7: Copy_References
public void Copy_References()
{
// WARNING! Do not use this code in a business app.
// This is not a valid use case of handling a Group membership but good enough for this test case.
EnsureNode("[TestRoot]/SourceFolder");
EnsureNode("[TestRoot]/TargetFolder");
var srcFolder = LoadNode("[TestRoot]/SourceFolder");
var group = new Group(srcFolder);
group.Name = "MyGroup";
group.AddReference("Members", Node.LoadNode(1));
group.AddReference("Members", Node.LoadNode(2));
group.Save();
CopyNode("[TestRoot]/SourceFolder/MyGroup", "[TestRoot]/TargetFolder");
group = (Group)LoadNode("[TestRoot]/TargetFolder/MyGroup");
group.ClearReference("Members");
group.AddReference("Members", Node.LoadNode(3));
group.AddReference("Members", Node.LoadNode(4));
group.AddReference("Members", Node.LoadNode(5));
group.Save();
var loadedSourceRefs = String.Join(",", (from r in LoadNode("[TestRoot]/SourceFolder/MyGroup").GetReferences("Members") orderby r.Id select r.Id.ToString()).ToArray());
var loadedTargetRefs = String.Join(",", (from r in LoadNode("[TestRoot]/TargetFolder/MyGroup").GetReferences("Members") orderby r.Id select r.Id.ToString()).ToArray());
Assert.AreEqual(loadedSourceRefs, "1,2");
Assert.AreEqual(loadedTargetRefs, "3,4,5");
}
示例8: Permission_20_PermissionsViaIndirectGroupMembership
public void Permission_20_PermissionsViaIndirectGroupMembership()
{
// 20.
// create a brand new file
File file = CreateBrandNewFile(RepositoryPath.Combine(Repository.Root.Path, "GroupTest.doc"));
int idOfFile = file.Id;
// create a group
string testGroupAName = "TestGroupA";
string testGroupAPath = RepositoryPath.Combine(Repository.Root.Path, testGroupAName);
if (Node.Exists(testGroupAPath))
Node.ForceDelete(testGroupAPath);
Group testGroupA = new Group(Repository.Root);
testGroupA.Name = testGroupAName;
testGroupA.AddMember(Dincsi);
testGroupA.Save();
string testGroupBName = "TestGroupB";
string testGroupBPath = RepositoryPath.Combine(Repository.Root.Path, testGroupBName);
if (Node.Exists(testGroupBPath))
Node.ForceDelete(testGroupBPath);
Group testGroupB = new Group(Repository.Root);
testGroupB.Name = testGroupBName;
testGroupB.AddMember(User.Administrator);
testGroupB.AddMember(testGroupA);
testGroupB.Save();
// Deny Open for the group
file.Security.SetPermission(testGroupA, true, PermissionType.Open, PermissionValue.Deny);
// Sould be denied for the user who is a member of the group
Assert.IsTrue(file.Security.GetPermission((IUser)Dincsi, PermissionType.Open) == PermissionValue.Deny);
// Allow Open for the group
file.Security.SetPermission(testGroupA, true, PermissionType.Open, PermissionValue.Allow);
// Sould be allowed for the user who is a member of the group
Assert.IsTrue(file.Security.GetPermission((IUser)Dincsi, PermissionType.Open) == PermissionValue.Allow);
}