Click or drag to resize

UserFactoryNewUser Method

Create a new user.

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public static IUser NewUser(
	IContext context
)

Parameters

context
Type: AskiaPortalCmnIContext
Context of execution

Return Value

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

Create a new user.

var context = ContextFactory.CreateByLoginAndPassword("login", "secret");   
var contextValidation = context.Validate();
if (!contextValidation.Success)
{
    throw contextValidation.Exception;
}

int validGroupId = 12;
var user = UserFactory.NewUser(context);
if (user == null)
{
    Console.Error.WriteLine("Could not create a user");
    return;
}
user.FirstName = "John";
user.LastName = "Doe";
user.Login = "JohnDoe";
user.Email = "johndoe@anonymous.com";
user.Membership.Add(validGroupId);
var saveResult = user.Save();
if (saveResult.Success)
{
    Console.WriteLine("The user `{0} {1}` (Id={2}) was successfully saved",
                                    user.FirstName, user.LastName, user.Id);
}
else
{
    Console.Error.Write(saveResult.Exception.Message);
}
See Also