public static bool IsInRoles(params string[] roles) { Models.Repository.UnitOfWork unitOfWork = new Models.Repository.UnitOfWork(); var user = unitOfWork.UsersRepo.Find(m => m.Id == UserId); if (user == null) { return(false); } if (string.IsNullOrEmpty(UserId)) { return(false); } return(user.UserRoles.Any(m => roles.Contains(m.Name))); }
public static bool IsInRoles(this IPrincipal principal, params string[] roles) { Models.Repository.UnitOfWork unitOfWork = new Models.Repository.UnitOfWork(); var userId = principal.Identity.GetUserId(); var user = unitOfWork.UsersRepo.Find(m => m.Id == userId); if (principal == null) { return(false); } if (user == null) { return(false); } if (string.IsNullOrEmpty(userId)) { return(false); } return(user.UserRoles.Any(m => roles.Contains(m.Name))); }