Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var usr = await _context.Users.FindAsync(id);



            if (usr != null)
            {
                userAndRoleViewModel = new UserAndRoleViewModel
                {
                    UserId   = usr.Id,
                    UserName = usr.UserName,
                    Roles    = await _userManager.GetRolesAsync(usr)
                };

                foreach (var role in userAndRoleViewModel.Roles)
                {
                    await _userManager.RemoveFromRoleAsync(usr, role);
                }


                //_context.Player.Remove(Player);
                //await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var usr = await _context.Users.FirstOrDefaultAsync(u => u.Id == id);

            if (usr == null)
            {
                return(NotFound());
            }

            //userAndRoleViewModel = new UserAndRoleViewModel();

            //userAndRoleViewModel.UserId = usr.Id;
            //userAndRoleViewModel.UserName = usr.UserName;
            //userAndRoleViewModel.Roles = await _userManager.GetRolesAsync(usr);

            userAndRoleViewModel = new UserAndRoleViewModel
            {
                UserId   = usr.Id,
                UserName = usr.UserName,
                Roles    = await _userManager.GetRolesAsync(usr)
            };

            //userAndRoleViewModel = Model;

            return(Page());
        }
Ejemplo n.º 3
0
        //ApplicationDbContext adb = new ApplicationDbContext();

        public ResponseModel <IEnumerable <UserAndRoleViewModel> > UserRole_Get()
        {
            List <UserAndRoleViewModel> reList = new List <UserAndRoleViewModel>();
            var list = db.AspNetUsers.Where(x => true);

            try
            {
                foreach (var item in list)
                {
                    UserAndRoleViewModel userRoleViewModel = new UserAndRoleViewModel();
                    var    s        = db.AspNetUserRoles.Where(x => x.UserId == item.Id).FirstOrDefault();
                    string roleName = null;
                    if (s != null)
                    {
                        roleName = db.AspNetRoles.Where(x => x.Id == s.RoleId).FirstOrDefault().Name;
                    }
                    else
                    {
                        roleName = "暂无";
                    }
                    userRoleViewModel.Id          = item.Id;
                    userRoleViewModel.RoleName    = roleName;
                    userRoleViewModel.UserName    = item.UserName;
                    userRoleViewModel.PhoneNumber = item.PhoneNumber;
                    userRoleViewModel.UserSex     = item.UserSex == "1" ? "男" : "女";
                    userRoleViewModel.PhoneNumber = item.PhoneNumber;
                    userRoleViewModel.Email       = item.Email;
                    userRoleViewModel.BirthDay    = item.BirthDay;
                    userRoleViewModel.Address     = item.Address;
                    userRoleViewModel.JobId       = item.JobId.ToLower();
                    var jobList = db.Job;
                    foreach (var job in jobList)
                    {
                        if (job.Id.ToString() == item.JobId.ToLower())
                        {
                            userRoleViewModel.JobName = job.Name;
                        }
                    }
                    reList.Add(userRoleViewModel);
                }
                reList.AsEnumerable();
            }
            catch (Exception e)
            {
                return(new ResponseModel <IEnumerable <UserAndRoleViewModel> >
                {
                    code = (int)code.GetUserRoleInfoFail,
                    data = null,
                    message = "用户角色信息获取失败," + e.Message
                });
            }
            return(new ResponseModel <IEnumerable <UserAndRoleViewModel> >
            {
                code = (int)code.Success,
                data = reList,
                message = ""//用户角色信息获取成功
            });
        }
Ejemplo n.º 4
0
        public UserAndRoleViewModel MakeUserChangesWithoutAdminRole(string id)
        {
            ApplicationUser user = this.Context.Users.Find(id);

            UserAndRoleViewModel userVm = new UserAndRoleViewModel();

            userVm.UserId = id;
            userVm.Email  = user.Email;

            userVm.Roles = this.Context.Roles.Where(r => r.Name != "Admin");
            return(userVm);
        }
Ejemplo n.º 5
0
        public UserAndRoleViewModel MakeUserChanges(string id)
        {
            ApplicationUser user = this.Context.Users.Find(id);

            UserAndRoleViewModel userVm = new UserAndRoleViewModel();

            userVm.UserId = id;
            userVm.Email  = user.Email;

            userVm.Roles = this.Context.Roles;

            return(userVm);
        }
Ejemplo n.º 6
0
        public async Task OnGetAsync()
        {
            var AllUsers = _context.Users.OrderBy(u => u.UserName).ToList();

            AllUsersAndRoles = new List <UserAndRoleViewModel>();


            foreach (var usr in AllUsers)
            {
                var model = new UserAndRoleViewModel
                {
                    UserId = usr.Id,

                    UserName = usr.UserName,

                    Roles = await _userManager.GetRolesAsync(usr)
                };

                AllUsersAndRoles.Add(model);
            }
        }