Пример #1
0
        public static bool IsUserInGroup(Guid userId, ApplicationRole.Role role)
        {
            using (ModManDbContext _context = new ModManDbContext())
            {
                Guid roleId = ApplicationRole.GetRoleId(role);
                ApplicationUserRole link = (from a in _context.ApplicationUserRoles where a.RoleId == roleId && a.UserId == userId select a).FirstOrDefault();

                if (link == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Пример #2
0
        public static Guid GetRoleId(Role role)
        {
            switch (role)
            {
            case Role.Admin:
                using (ModManDbContext _context = new ModManDbContext())
                {
                    return((from b in _context.ApplicationRoles where b.Name == "Admin" select b.Id).Single());
                }

            case Role.User:
                using (ModManDbContext _context = new ModManDbContext())
                {
                    return((from b in _context.ApplicationRoles where b.Name == "User" select b.Id).Single());
                }

            default:
                throw new NotImplementedException("Unknown role: " + role.ToString());
            }
        }