Esempio n. 1
0
        public override string[] GetRolesForUser(string login)
        {
            string[] role = new string[] { };
            using (UserContext context = new UserContext())
            {
                try
                {
                    User user = (from u in context.Users
                                 where u.Login == login
                                 select u).FirstOrDefault();
                    if (user!=null)
                    {
                        Role userRole = context.Roles.Find(user.RoleId);

                        if (userRole!=null)
                        {
                            role = new string[] { userRole.Name };
                        }
                    }
                }
                catch (Exception)
                {
                    role = new string[] { };
                }
            }
            return role;
        }
Esempio n. 2
0
 public override bool IsUserInRole(string login, string roleName)
 {
     bool outputResult = false;
     using (UserContext context = new UserContext())
     {
         try
         {
             User user = (from u in context.Users
                          where u.Login == login
                          select u).FirstOrDefault();
             if (user!=null)
             {
                 Role userRole = context.Roles.Find(user.RoleId);
                 if (userRole!= null && userRole.Name == roleName)
                 {
                     outputResult = true;
                 }
             }
         }
         catch (Exception)
         {
             outputResult = false;
         }
     }
     return outputResult;
 }