IUserPromoteAsSuperAdmin Method |
Namespace: AskiaPortalCmn
This example show how to promote a user as a super-administrator
using system; using AskiaPortalCmn; namespace MyApp { class Program { static void Main(string[] args) { var context = ContextFactory.CreateByLoginAndPassword("login", "secret"); var contextValidation = context.Validate(); if (!contextValidation.Success) { Console.Error.WriteLine("Invalid context"); Console.Error.Write(contextValidation.Exception.Message); return; } IUser userToPromote = UserFactory.FindByGuid(context, Guid.Parse("20BE5F84-F006-49A0-9674-4B16A090AF2D")); if (userToPromote == null) { Console.Error.WriteLine("Could not find the user with the specified guid"); return; } var promoteResult = userToPromote.PromoteAsSuperAdmin(); if (!promoteResult.Success) { Console.Error.WriteLine("Could not promote the user as a super administrator"); Console.Error.WriteLine(promoteResult.Exception.Message); return; } var saveResult = userToPromote.Save(); if (saveResult.Success) { Console.WriteLine("The user `{0}` is now a super administrator, IsSuperAdmin={1}", userToPromote.LastName, userToPromote.IsSuperAdmin); // --> Produce // "The user `Doe` is now a super administrator, IsSuperAdmin=True" } else { Console.Error.WriteLine("Could not save the promoted user"); Console.Error.WriteLine(saveResult.Exception.Message); } } } }