コード例 #1
0
 public override string[] GetAllRoles()
 {
     using (var FundRaisingDBContext = new FundRaisingDBContext())
     {
         return(FundRaisingDBContext.Roles.Select(r => r.RoleName).ToArray());
     }
 }
コード例 #2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // Ensure ASP.NET Simple Membership is initialized only once per app start
            LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);

            FundRaisingDBContext db = new FundRaisingDBContext();
        }
コード例 #3
0
        public override string[] GetRolesForUser(string username)
        {
            using (var FundRaisingDBContext = new FundRaisingDBContext())
            {
                var user = FundRaisingDBContext.Students.SingleOrDefault(u => u.StudentID == username);

                if (user == null)
                {
                    var adminuser = FundRaisingDBContext.Distributors.SingleOrDefault(x => x.UserName == username);
                    if (adminuser == null)
                    {
                        return(new string[] { });
                    }
                    else
                    {
                        var roles        = FundRaisingDBContext.UserRoles.Where(x => x.UserId == adminuser.userID).Select(x => x.RoleId).ToArray();
                        var selectedrole = (from role in FundRaisingDBContext.Roles where roles.Contains(role.RoleId) select role);
                        var roletoUser   = selectedrole.Select(x => x.RoleName).ToArray();
                        return(roles == null ? new string[] { } : roletoUser);
                    }



                    ///code to Give access to Role - Admin
                    ///--------------------------------------------------//////
                    // var users = FundRaisingDBContext.Distributors.SingleOrDefault(u => u.UserName == username);
                    //if(users==null)
                    //{
                    //    return new string[] { };
                    //}
                    //else
                    //{
                    //    var role = FundRaisingDBContext.UserRoles.Where(x => x.UserId == users.userID).Select(x => x.RoleId).ToArray();
                    //    var selectedroles = (from rol in FundRaisingDBContext.Roles where role.Contains(rol.RoleId) select rol);
                    //    var roletoUsers = selectedroles.Select(x => x.RoleName).ToArray();
                    //    //var rolesarray=allroles.ToArray();

                    //    return role == null ? new string[] { } : roletoUsers;
                    //}
                    ///--------------------------------------------------//////
                }
                else
                {
                    var roles        = FundRaisingDBContext.UserRoles.Where(x => x.UserId == user.ID).Select(x => x.RoleId).ToArray();
                    var selectedrole = (from role in FundRaisingDBContext.Roles where roles.Contains(role.RoleId) select role);
                    var roletoUser   = selectedrole.Select(x => x.RoleName).ToArray();
                    return(roles == null ? new string[] { } : roletoUser);
                }

                //var rolesarray=allroles.ToArray();


                return(new string[] { });
            }
        }
コード例 #4
0
        public override bool IsUserInRole(string username, string roleName)
        {
            using (var DB = new FundRaisingDBContext())
            {
                var user = DB.Students.SingleOrDefault(u => u.StudentID == username);
                if (user == null)
                {
                    return(false);
                }
                var roles    = DB.UserRoles.Where(x => x.UserId == user.ID);
                var roleInfo = DB.Roles.Where(x => x.RoleName == roleName);

                return(roles != null && roleInfo != null);
            }
        }