Exemplo n.º 1
0
        public List <SelectListItem> UserRolesSelectList()
        {
            List <Role> roles = _roleAppService.GetAllRoles();

            return(roles.Select(x => new SelectListItem {
                Value = x.Id.ToString(), Text = x.Name
            }).ToList());
            //return _stateAppService.GetSimpleList().Select(p => new SelectListItem { Value = p.StateAbbreviation, Text = p.Name }).ToList().AsEnumerable();
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetRolesForSelect()
        {
            var roles = await _roleAppService.GetAllRoles();

            var json = roles.Select(a => new SelectViewModel
            {
                Id   = a.Id,
                Text = a.Name
            });

            return(Json(json));
        }
        public JsonResult GetRoles()
        {
            if (HttpContext.Request.IsAjaxRequest())
            {
                var model = _roleAppService.GetAllRoles()
                            .Select((r, i) => new RoleViewModel()
                {
                    SId                  = i + 1,
                    Id                   = r.Id,
                    Name                 = r.Name,
                    IsDefault            = r.IsDefault,
                    CreationTime         = r.CreationTime.ToStandardDateOfChina(),
                    LastModificationTime = r.LastModificationTime?.ToStandardDateOfChina()
                });

                return(Json(model));
            }
            throw new JMBasicException("访问出错");
        }
        public JsonResult GetUserRolesByUserId(int id)
        {
            var userRoleIds = _roleAppService.GetAllRolesByUserId(id)
                              .Select(r => r.Id);

            if (HttpContext.Request.IsAjaxRequest())
            {
                var model = _roleAppService.GetAllRoles()
                            .Select((r, i) => new UserRoleViewModel()
                {
                    SId       = i + 1,
                    Id        = r.Id,
                    RoleName  = r.Name,
                    IsDefault = r.IsDefault,
                    HasOwned  = userRoleIds.Contains(r.Id)
                });

                return(Json(model));
            }
            throw new JMBasicException("访问出错");
        }