Example #1
0
        public async Task <IActionResult> ListRoles([FromQuery] RolesQuery request)
        {
            try
            {
                var result = await _service.GetRoles(request);

                return(Ok(result));
            }
            catch (BusinessLogicException ex)
            {
                return(BadRequest(new Response
                {
                    Status = false,
                    Message = ex.Message
                }));
            }
            catch (Exception e)
            {
                return(BadRequest(new Response
                {
                    Status = false,
                    Message = ErrorMessages.UnkownError
                }));
            }
        }
Example #2
0
        public async Task <Response <RolesDtoWithoutPagenated> > GetRolesAll(RolesQuery request)
        {
            var result = _roleManager.Roles.AsQueryable();

            if (!string.IsNullOrEmpty(request.Name))
            {
                result = result.Where(x => x.Name.Contains(request.Name));
            }

            ///pagenating
            int take = request.PageSize;
            int skip = (request.PageId - 1) * take;

            int totalPages = (int)Math.Ceiling(result.Count() / (double)take);

            var finalResult = result.OrderBy(x => x.Name).Skip(skip).Take(take).AsQueryable();
            //----------------

            var resultData = new RolesDtoWithoutPagenated
            {
                Dtos = await finalResult.Select(r => new RoleDto
                {
                    Id   = r.Id,
                    Name = r.Name
                }).ToListAsync()
            };

            return(new Response <RolesDtoWithoutPagenated>
            {
                Data = resultData,
                Status = true,
                Message = "success"
            });
        }
Example #3
0
        public IReadOnlyCollection <Role> GetRoles()
        {
            var        query      = new RolesQuery(dbContext.Roles);
            RoleMapper roleMapper = new RoleMapper();

            return(roleMapper.Map(query.Execute()).ToList());
        }
Example #4
0
        public IActionResult ManageRoles(int?pageIndex, int pageSize = 20)
        {
            NameValueCollection from       = RequestHelper.GetQueryParams(Request);
            RolesQuery          rolesQuery = new RolesQuery();

            rolesQuery.Keyword = from["keyWord"];

            string isEnabled = from["isEnabled"],
                   isPublic  = from["isPublic"],
                   isBuiltin = from["isBuiltin"];

            if (!string.IsNullOrWhiteSpace(rolesQuery.Keyword))
            {
                ViewData["Keyword"] = rolesQuery.Keyword;
            }
            if (!string.IsNullOrWhiteSpace(isEnabled))
            {
                rolesQuery.IsEnabled = isEnabled.AsBool();
            }
            if (!string.IsNullOrWhiteSpace(isBuiltin))
            {
                rolesQuery.IsBuiltin = isBuiltin.AsBool();
            }
            if (!string.IsNullOrWhiteSpace(isPublic))
            {
                rolesQuery.IsPublic = isPublic.AsBool();
            }

            Dictionary <bool, string> enabledValues = new Dictionary <bool, string> {
                { true, "已启用" }, { false, "未启用" }
            };

            ViewData["IsEnabled"] = new SelectList(enabledValues.Select(m => new { text = m.Value, value = m.Key.ToString().ToLower() }), "value", "text", rolesQuery.IsEnabled);

            Dictionary <bool, string> publicValues = new Dictionary <bool, string> {
                { true, "已公开" }, { false, "未公开" }
            };

            ViewData["IsPublic"] = new SelectList(publicValues.Select(m => new { text = m.Value, value = m.Key.ToString().ToLower() }), "value", "text", rolesQuery.IsPublic);

            Dictionary <bool, string> builtinValues = new Dictionary <bool, string> {
                { true, "是" }, { false, "否" }
            };

            ViewData["IsBuiltin"] = new SelectList(builtinValues.Select(m => new { text = m.Value, value = m.Key.ToString().ToLower() }), "value", "text", rolesQuery.IsBuiltin);

            pageIndex             = pageIndex ?? 1;
            rolesQuery.RoleSortBy = RoleSortBy.Rolename;

            PagingDataSet <Roles> rolesPaging = rolesService.GetRoles(rolesQuery, pageIndex.Value, pageSize);

            if (pageIndex > 1 && (rolesPaging == null || rolesPaging.Count() == 0))
            {
                rolesPaging = rolesService.GetRoles(rolesQuery, pageSize, pageIndex.Value - 1);
            }

            return(View(rolesPaging));
        }
 public UserCollection(RolesQuery query, int total, IEnumerable <RoleAssignments> items) : base(query, total, items)
 {
 }
 protected override UserCollection GetUserCollection(RolesQuery query, int total, IEnumerable <RoleAssignments> users)
 {
     return(new UserCollection(query, total, users));
 }
Example #7
0
 /// <summary>
 /// 查询
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public List <RolesTb> Query(RolesQuery query)
 {
     return(_service.Query(query));
 }