Esempio n. 1
0
        public static RoleDTO GetRoleDTO(RoleTypes roleType)
        {
            var role = new RoleDTO
            {
                RoleName             = roleType.ToString(),
                RoleDescription      = EnumUtil.GetEnumDesc(roleType),
                RoleDescriptionShort = roleType.ToString()
            };

            return(role);
        }
Esempio n. 2
0
        /// <summary>
        /// Get the name of a role
        /// </summary>
        /// <param name="en">Type of role</param>
        /// <returns>Name of the role</returns>
        public static string GetRoleName(RoleTypes en)
        {
            Type type = en.GetType();

            MemberInfo[] memberInfo = type.GetMember(en.ToString());

            if (memberInfo != null && memberInfo.Length > 0)
            {
                object[] attributes = memberInfo[0].GetCustomAttributes(typeof(Name), false);
                if (attributes != null && attributes.Length > 0)
                {
                    return(((Name)attributes[0]).Text);
                }
            }
            return(en.ToString());
        }
Esempio n. 3
0
        public Account AddRole(int accountId, RoleTypes role)
        {
            var account   = DbSet.First(a => a.Id == accountId);
            var roleToAdd = _context.Roles.First(r => r.Name == role.ToString());

            account.Roles.Add(roleToAdd);
            _context.SaveChanges();
            return(account);
        }
Esempio n. 4
0
        private async Task <User> CreateAspUser(SchoolUser schoolUser, RoleTypes role)
        {
            var accountRegister = new FullRegisterInputModel
            {
                Pin       = schoolUser.Pin,
                FirstName = schoolUser.FirstName,
                LastName  = schoolUser.LastName,
                RoleName  = role.ToString()
            };

            return(await _accountService.Register(accountRegister));
        }
Esempio n. 5
0
        public static IProvideMetadata AddPermission(this IProvideMetadata type, RoleTypes permission)
        {
            var permissions = type.GetMetadata <List <string> >(PermissionsKey);

            if (permissions == null)
            {
                permissions = new List <string>();
                type.Metadata[PermissionsKey] = permissions;
            }

            permissions.Fill(permission.ToString());

            return(type);
        }
Esempio n. 6
0
 public static bool UserHasRole(RoleTypes role) //int userId,
 {
     return(Singleton.User.Roles.Any(u => u.Role.RoleName == role.ToString()));
 }
Esempio n. 7
0
 public static bool UserHasRole(RoleTypes role)
 {
     return(Singleton.User.Roles.Any(u => u.Role.RoleDescriptionShort == role.ToString()));
 }
Esempio n. 8
0
        public static bool HasPermission(this IProvideMetadata type, RoleTypes permission)
        {
            var permissions = type.GetMetadata <IEnumerable <string> >(PermissionsKey, new List <string>());

            return(permissions.Any(x => string.Equals(x, permission.ToString())));
        }
Esempio n. 9
0
 public static string GetRoleName(this RoleTypes role)
 {
     return(role.ToString());
 }
 public static string GetPermissionName(this RoleTypes roleType)
 {
     return($"{ClaimType}.{roleType.ToString()}");
 }