Click or drag to resize

IUserPromoteAsSuperAdmin Method

Promote the user as 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 PromoteAsSuperAdmin()

Return Value

Type: IReturnValue
Returns true if the user in the context have enough right to promote a user (it should be a super-admin himself)
Remarks
A non super-administrator cannot promote another user as 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 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);
                }
         }
    }
}
See Also