示例#1
0
        public ICollection <UserViewModel> GetUsers()
        {
            var Users = _context.GetUsers();

            ICollection <UserViewModel> usersView = new List <UserViewModel>();

            foreach (var user in Users)
            {
                var UserRoles = _userManager.GetRolesAsync(user).Result;

                UserViewModel singleUserView = new UserViewModel
                {
                    Email     = user.Email,
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    Address   = user.Address,
                    Role      = UserRoles.FirstOrDefault()
                };

                if (singleUserView.Role == Enum.GetName(typeof(AvailableRoles), 1))
                {
                    singleUserView.Role = "Użytkownik";
                }
                else
                {
                    singleUserView.Role = "Administrator";
                }

                usersView.Add(singleUserView);
            }

            return(usersView);
        }