Esempio n. 1
0
        public async Task <IActionResult> IndexAsync()
        {
            IList <string>         roles;
            List <IList <string> > userRoles = new List <IList <string> >();

            // Get list of roles for each user
            foreach (var user in _userManager.Users)
            {
                roles = await _userManager.GetRolesAsync(user);

                if (roles.Count == 0)
                {
                    roles = new List <string>()
                    {
                        "N/A"
                    };
                }
                userRoles.Add(roles);
            }

            ViewUsersViewModel viewUsersViewModel = new ViewUsersViewModel
            {
                Users = _context.Users.Include(u => u.PaymentProfile).ToList(),
                Roles = userRoles
            };

            return(View(viewUsersViewModel));
        }
        public async Task <IActionResult> ViewUsers(ViewUsersViewModel ViewModel) // POST to add new user
        {
            // Gets the current user
            var currentuser = await GetCurrentUserAsync();

            // The user's customer ID is used to retrieve all other users.
            var users = _userService.GetUsersWithCustomerId(currentuser.CustomerId);

            ViewModel.Users = users;

            // If the form in the view is valid
            if (ModelState.IsValid)
            {
                var model  = ViewModel.RegisterUserViewModel;
                var result = await _userService.AddUserAsync(model, currentuser.CustomerId);

                users                    = _userService.GetUsersWithCustomerId(currentuser.CustomerId);
                ViewModel.Users          = users;
                ViewModel.AvailableRoles = _roleService.GetRoles();

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }

                return(View(ViewModel));
            }
            return(View(ViewModel));
        }
        public async Task <IActionResult> ViewUsers()
        {
            // Gets the current user
            var user = await GetCurrentUserAsync();

            // The user's customer ID is used to retrieve all other users.
            var users = _userService.GetUsersWithCustomerId(user.CustomerId);

            // populates the view model to be returned to the view
            ViewUsersViewModel ViewModel = new ViewUsersViewModel()
            {
                Users          = users,
                AvailableRoles = _roleService.GetRoles()
            };

            return(View(ViewModel));
        }
Esempio n. 4
0
        public ActionResult ViewUsers()
        {
            IEnumerable <User>        users      = usersService.GetAll();
            List <ViewUsersViewModel> viewModels = new List <ViewUsersViewModel>();

            foreach (User user in users)
            {
                ViewUsersViewModel viewModel = new ViewUsersViewModel();
                viewModel.Email   = user.Email;
                viewModel.IsAdmin = user.IsAdmin;
                viewModel.Name    = user.Name;
                viewModel.UserId  = user.UserId;
                viewModels.Add(viewModel);
            }

            return(View(viewModels));
        }