コード例 #1
0
        public GetAllUserResponse GetAllUsers()
        {
            GetAllUserResponse response = new GetAllUserResponse();

            IEnumerable <User> users = _userRepository
                                       .FindAll();

            if (users != null)
            {
                response.UserFound = true;
                response.Users     = users.ConvertToUserViews();
            }
            else
            {
                response.UserFound = false;
            }


            return(response);
        }
コード例 #2
0
        public async Task <GetAllUserResponse> GetAllUsers()
        {
            var result    = new GetAllUserResponse();
            var userRoles = await _userRepository.GetAlUserRoles();

            var roles = _roleManager.Roles.ToList();
            var users = _userManager.Users.ToList();

            foreach (var role in roles)
            {
                var usersInRole = userRoles.FindAll(user => user.RoleId == role.Id).ToList();
                foreach (var userInRole in usersInRole)
                {
                    var userWithRole = users.Find(user => user.Id == userInRole.UserId);
                    var userResponse = _mapper.Map <ApplicationUser, UserResponse>(userWithRole);
                    userResponse.UserRole = (UserRoleModel)Enum.Parse(typeof(UserRoleModel), role.Name);
                    result.Users.Add(userResponse);
                }
            }
            return(result);
        }