Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id)
        {
            var user = await permissionService.GetAppUserByIdAsync(id);

            if (user == null)
            {
                return(NotFound());
            }

            var  model = new UserEditForm();
            bool edit  = true;

            model.permissionOptions = await GetPermissionOptions(edit);

            var permissions = await permissionService.GetUserPermissionsAsync(user);

            var userModel = PermissionViewService.MapUserViewModel(user, permissions.ToList());

            userModel.permissionIds = permissions.Select(p => p.Id).ToArray();



            model.user = userModel;

            return(new ObjectResult(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(int permission = 0, string keyword = "", int page = 1, int pageSize = 10)
        {
            Permission selectedPermission = null;

            if (permission > 0)
            {
                selectedPermission = await permissionService.GetPermissionByIdAsync(permission);
            }
            if (selectedPermission == null)
            {
                permission = 0;
            }

            var users = await permissionService.FetchUsersWithPermissions(selectedPermission, keyword);

            users = users.OrderByDescending(u => u.LastUpdated);

            var pageList = new PagedList <AppUser, UserViewModel>(users, page, pageSize);

            foreach (var user in pageList.List)
            {
                var permissions = await permissionService.GetUserPermissionsAsync(user);

                pageList.ViewList.Add(PermissionViewService.MapUserViewModel(user, permissions.ToList()));
            }

            pageList.List = null;


            if (Request.IsAjaxRequest())
            {
                return(new ObjectResult(pageList));
            }

            string token = await GetToken();

            ViewData["token"] = token;

            bool edit = false;
            var  permissionsOptions = await GetPermissionOptions(edit);

            permissionsOptions.Insert(0, new PermissionOption {
                text = "----------", value = 0
            });

            ViewData["permissions"] = this.ToJsonString(permissionsOptions);


            ViewData["list"] = this.ToJsonString(pageList);

            return(View());
        }