public static RoleDTO GetRoleDTO(RoleTypes roleType) { var role = new RoleDTO { RoleName = roleType.ToString(), RoleDescription = EnumUtil.GetEnumDesc(roleType), RoleDescriptionShort = roleType.ToString() }; return(role); }
/// <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()); }
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); }
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)); }
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); }
public static bool UserHasRole(RoleTypes role) //int userId, { return(Singleton.User.Roles.Any(u => u.Role.RoleName == role.ToString())); }
public static bool UserHasRole(RoleTypes role) { return(Singleton.User.Roles.Any(u => u.Role.RoleDescriptionShort == role.ToString())); }
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()))); }
public static string GetRoleName(this RoleTypes role) { return(role.ToString()); }
public static string GetPermissionName(this RoleTypes roleType) { return($"{ClaimType}.{roleType.ToString()}"); }