Click or drag to resize

IUserDemoteASuperAdmin Method

Demote a super-administrator.
It will not save the change in the database unless you explicitly call the Save method

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
IReturnValue DemoteASuperAdmin()

Return Value

Type: IReturnValue
Returns true if the user in the context have enough right to demote a super administrator(it should be a super-admin himself)
Remarks
A non super-administrator cannot demote a super-administrator.
It will not save the change in the database unless you explicitly call the Save method
Examples

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);
                    }
             }
        }
    }
See Also