IUserDemoteASuperAdmin Method |
Namespace: AskiaPortalCmn
This example show how to demote 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 userToDemote = UserFactory.FindByGuid(context, Guid.Parse("20BE5F84-F006-49A0-9674-4B16A090AF2D")); if (userToDemote == null) { Console.Error.WriteLine("Could not find the user with the specified guid"); return; } var demoteResult = userToDemote.DemoteASuperAdmin(); if (!demoteResult.Success) { /// Console.Error.WriteLine("Could not demote the super administrator"); Console.Error.WriteLine(demoteResult.Exception.Message); return; } var saveResult = userToDemote.Save(); if (saveResult.Success) { Console.WriteLine("The user `{0}` is not a super administrator anymore, IsSuperAdmin={1}", userToDemote.LastName, userToDemote.IsSuperAdmin); // --> Produce // "The user `Doe` is not a super administrator anymore, IsSuperAdmin=False" } else { Console.Error.WriteLine("Could not save the demote user"); Console.Error.WriteLine(saveResult.Exception.Message); } } } }