Beispiel #1
0
 internal string[] GetUsersInRole(string rolename, out string msg)
 {
     try
     {
         msg = "";
         var userIds = new UserRoleRepository().GetUserRolesByRoleId(GetRoles().Where(p => String.Compare(p.Name.Trim(), rolename.Trim(), StringComparison.CurrentCultureIgnoreCase) == 0).ToList()[0].RoleId).Select(m => m.UserId).ToList();
         if (!userIds.Any())
         {
             return(null);
         }
         return(new UserRepository().GetUsers().Where(m => userIds.Contains(m.UserId)).Select(q => q.Username).ToArray());
     }
     catch (DbEntityValidationException ex)
     {
         BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
         msg = ex.Message;
         return(null);
     }
     catch (Exception ex)
     {
         BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
         msg = ex.Message;
         return(null);
     }
 }
Beispiel #2
0
 public int[] GetRoleIdsForUser(string username, out string msg)
 {
     try
     {
         msg = "";
         var roleIds = new UserRoleRepository().GetUserRolesByUserId(new UserRepository().GetUser(username).UserId).Select(l => l.RoleId).ToList();
         if (roleIds.Count < 1)
         {
             return(null);
         }
         var roles = GetRoles().Where(m => roleIds.Contains(m.RoleId)).ToList().Select(m => m.RoleId).ToArray();
         return(roles);
     }
     catch (DbEntityValidationException ex)
     {
         msg = ex.Message;
         return(null);
     }
     catch (Exception ex)
     {
         msg = ex.Message;
         return(null);
     }
 }