Exemplo n.º 1
0
        private IEnumerable <ShowUsersViewModel> ParseUserViews(List <User> users)
        {
            List <ShowUsersViewModel> returnedModel = new List <ShowUsersViewModel>();

            foreach (User item in users)
            {
                ShowUsersViewModel itemViewModel = new ShowUsersViewModel();
                itemViewModel.UserId    = item.UserId;
                itemViewModel.Login     = item.Login;
                itemViewModel.Password  = item.Password;
                itemViewModel.Email     = item.Email;
                itemViewModel.UserRoles = "";
                List <UserRole> userRoles = _userProvider.GetUserRolesByUserId(itemViewModel.UserId);
                foreach (UserRole role in userRoles)
                {
                    itemViewModel.UserRoles = itemViewModel.UserRoles + role.Name + ", ";
                }
                itemViewModel.UserRoles = itemViewModel.UserRoles.TrimEnd();
                int ind = itemViewModel.UserRoles.LastIndexOf(",");
                if (ind == itemViewModel.UserRoles.Length - 1)
                {
                    itemViewModel.UserRoles = itemViewModel.UserRoles.Remove(itemViewModel.UserRoles.Length - 1, 1);
                }
                returnedModel.Add(itemViewModel);
            }
            return(returnedModel);
        }
Exemplo n.º 2
0
        public ActionResult ShowUsers()
        {
            if (User.Identity.Name != "*****@*****.**")
            {
                return(HttpNotFound());
            }
            var viewModel = new ShowUsersViewModel
            {
                Users = _context.Users.ToList(),
                Roles = new List <String>()
            };

            foreach (var user in viewModel.Users)
            {
                if (UserManager.IsInRole(user.Id, "User"))
                {
                    viewModel.Roles.Add("User");
                }
                else
                {
                    viewModel.Roles.Add("Admin");
                }
            }

            var index = viewModel.Users.FindIndex(c => c.UserName == "*****@*****.**");

            viewModel.Users.RemoveAt(index);
            viewModel.Roles.RemoveAt(index);

            return(View(viewModel));
        }
        public ViewResult ShowUsers()
        {
            ShowUsersViewModel model = new ShowUsersViewModel();

            model.Users = repository.GetAllUsers();

            return(View(model));
        }
Exemplo n.º 4
0
        public ActionResult GetUsersForSite(int id)
        {
            var users = this.siteService.GetById(id).Users.
                        ToList().ConvertAll(x =>
                                            new ShowUserViewModel
            {
                Id   = x.Id,
                Name = (x.FirstName != null && x.SecondName != null && x.LastName != null) ?
                       x.FirstName + " " + x.SecondName + " " + x.LastName : x.Email
            });

            var viewMode = new ShowUsersViewModel
            {
                SiteId = id,
                Users  = users
            };

            return(View(viewMode));
        }
Exemplo n.º 5
0
        public ActionResult GetAllUsers()
        {
            string[] roles;
            int      i        = 0;
            var      users    = userService.GetAllByPredicate(u => u.UserName != User.Identity.Name);
            var      mvcUsers = users.Select(u => u.ToMvcAllUsers());

            ShowUsersViewModel[] newUsers = new ShowUsersViewModel[mvcUsers.Count()];
            foreach (var mvcUser in mvcUsers)
            {
                roles             = userService.GetRolesForUser(mvcUser.UserName);
                mvcUser.RoleNames = string.Join(",", roles);
                newUsers[i]       = new ShowUsersViewModel {
                    Id = mvcUser.Id, Email = mvcUser.Email, UserName = mvcUser.UserName, RoleNames = string.Join(",", roles)
                };
                i++;
            }
            if (Request.IsAjaxRequest())
            {
                return(PartialView("_ShowAllUsers", newUsers));
            }
            return(View("_ShowAllUsers", mvcUsers));
        }