UserFactoryNewUser Method |
Namespace: AskiaPortalCmn
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); }