Click or drag to resize

GroupFactoryNewChildGroup Method

Create a new empty child instance of group

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public static IGroup NewChildGroup(
	IContext context,
	IGroup parentGroup
)

Parameters

context
Type: AskiaPortalCmnIContext
Context of execution
parentGroup
Type: AskiaPortalCmnIGroup
Parent group

Return Value

Type: IGroup
Return a new empty group or null if the user in the context doesn't have enough right to create a child group
Examples

Create a child group and save it

var context = ContextFactory.CreateByUserGuid(Guid.Parse("20BE5F84-F006-49A0-9674-4B16A090AF2D"));   
var contextValidation = context.Validate();
if (!contextValidation.Success)
{
    throw contextValidation.Exception;
}

var parentGroup = GroupFactory.FindById(context, 3);
if (parentGroup == null)
{
    Console.Error.WriteLine("Could not find the parent group");
    return;
}

var group = GroupFactory.NewChildGroup(context, parentGroup);
if (group == null)
{
    Console.Error.WriteLine("Could not create a child group");
    return;
}
group.Name = "My child group";
var saveResult = group.Save();
if (saveResult.Success)
{
    Console.WriteLine("The group `{0}` (Id={1}) was successfully saved",
                                    group.Name, group.Id);
}
else
{
    Console.Error.WriteLine("Unable to save the group");
    Console.Error.Write(saveResult.Exception.Message);
}
See Also