Click or drag to resize

IUserProfilePermissions Property

Indicates the permissions of the user profile.

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
IPermissions Permissions { get; }

Property Value

Type: IPermissions
Examples

This example looks the user profile permission of the user in the context.

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;
                }

                if (!Context.User.UserProfileId.HasValue)
                {
                    Console.Error.WriteLine("The user doesn't have a user profile attached to him");
                    return;
                }
                var profile = UserProfileFactory.FindById(context, Context.User.UserProfileId.Value);
                switch (profile.Permissions[AccessTo.Users])
                {
                    case AccessLevel.None:
                        Console.WriteLine("The user profile don't have permission to access users");
                        break;
                    case AccessLevel.ReadOnly:
                        Console.WriteLine("The user profile can only view users");
                        break;
                    case AccessLevel.CreateAndEdit:
                        Console.WriteLine("The user profile are allowed to view, create, edit users");
                        break;
                    case AccessLevel.FullControl:
                        Console.WriteLine("The user profile have full control on users (view, create, edit, delete and restore)");
                        break;
                }
         }
    }
}
See Also