コード例 #1
0
ファイル: HomeController.cs プロジェクト: amoryjh/MVC-HPFS
        //Get Index page
        public ActionResult Index()
        {
            var userRoles = new List<RolesViewModel>();
            var userStore = new UserStore<ApplicationUser>(context);
            var userManager = new UserManager<ApplicationUser>(userStore);

            //Get all the usernames
            foreach (var user in userStore.Users)
            {
                var r = new RolesViewModel
                {
                    UserName = user.UserName
                };
                userRoles.Add(r);
            }
            //Get all the Roles for our users
            foreach (var user in userRoles)
            {
                user.RoleNames = userManager.GetRoles(userStore.Users.First(s => s.UserName == user.UserName).Id);

                if (user.RoleNames.Contains("Default"))
                {
                    TempData["ValidationMessageIcon"] = "1";
                }
            }

            return View(db.Indices.ToList());
        }
コード例 #2
0
ファイル: UserController.cs プロジェクト: amoryjh/MVC-HPFS
        public ActionResult Index()
        {
            var userRoles = new List<RolesViewModel>();
            var userStore = new UserStore<ApplicationUser>(context);
            var userManager = new UserManager<ApplicationUser>(userStore);

            //Get all the usernames
            foreach (var user in userStore.Users)
            {
                var r = new RolesViewModel
                {
                    UserName = user.UserName
                };
                userRoles.Add(r);
            }
            //Get all the Roles for our users

            var numberOfDefault = 0;

            foreach (var user in userRoles)
            {
                user.RoleNames = userManager.GetRoles(userStore.Users.First(s => s.UserName == user.UserName).Id);

                if(user.RoleNames.Contains("Default"))
                {
                    numberOfDefault++;
                    TempData["ValidationMessageDefaultUser"] = numberOfDefault + " " + "New User(s) Have Registered";
                    TempData["ValidationMessageIcon"] = "1";
                }
            }

            return View(userRoles);
        }