Beispiel #1
0
        public List <ViewUserList> GetUsers()
        {
            List <ViewUserList> users = new List <ViewUserList>();

            try
            {
                var identityUsers = _userManager.Users;
                foreach (IdentityUser user in identityUsers)
                {
                    List <string> roleNamesList = GetRolesByUser(user);
                    string        roleNames     = string.Join(",", roleNamesList);

                    ViewUserList viewUser = new ViewUserList
                    {
                        Email = user.Email,
                        Name  = user.UserName,
                        Roles = roleNames
                    };
                    users.Add(viewUser);
                }
            }
            catch (Exception err)
            {
                Debug.WriteLine($"Error: {err.Message}");
            }
            return(users);
        }
Beispiel #2
0
        public IActionResult Edit(ViewUserList user)
        {
            bool updated = _userRepository.UpdateCommonUserData(user);

            if (updated != true)
            {
                return(RedirectToAction("Edit"));
            }
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #3
0
        public bool UpdateCommonUserData(ViewUserList user)
        {
            bool dataUpdated = false;

            try
            {
                IdentityUser identityUser = _userManager.FindByEmailAsync(user.Email).Result;
                if (identityUser != null)
                {
                    identityUser.Email    = user.Email;
                    identityUser.UserName = user.Name;
                    _dbContext.Users.Update(identityUser);
                    _dbContext.SaveChanges();
                    dataUpdated = true;
                }
            }
            catch (Exception err)
            {
                Debug.WriteLine($"Error: {err.Message}");
            }
            return(dataUpdated);
        }
 public Task <IViewComponentResult> InvokeAsync(ViewUserList user)
 {
     return(Task.FromResult <IViewComponentResult>(View("UserItem", user)));
 }