예제 #1
0
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="input">过滤条件</param>
        /// <returns></returns>
        public async Task <PagedResultDto <RoleListDto> > GetPagedAsync(GetRoleInput input)
        {
            List <string> wheres     = new List <string>();
            List <object> parameters = new List <object>();
            int           index      = 0;

            if (!String.IsNullOrEmpty(input.Name))
            {
                wheres.Add($"Name.Contains(@{index++})");
                parameters.Add(input.Name);
            }
            if (!String.IsNullOrEmpty(input.Date))
            {
                DateTime[] date = Array.ConvertAll(input.Date
                                                   .Split(new[] { '~' }, StringSplitOptions.RemoveEmptyEntries)
                                                   , DateTime.Parse);
                wheres.Add($"AddTime > (@{index++}) AND AddTime < (@{index++})");
                parameters.Add(date[0]);
                parameters.Add(date[1]);
            }
            if (!String.IsNullOrEmpty(input.Sorting))
            {
                input.Sorting = input.Sorting + (input.Order == OrderType.ASC ? " ASC" : " DESC");
            }
            var result = await CurrentRepository
                         .GetPagedAsync(input.PageIndex, input.PageSize,
                                        String.Join(" AND ", wheres), parameters.ToArray(), input.Sorting);

            return(new PagedResultDto <RoleListDto>()
            {
                Items = _mapper.Map <List <RoleListDto> >(result.Item1),
                TotalCount = result.Item2
            });
        }
예제 #2
0
 public GetRoleOutput GetRole(GetRoleInput input)
 {
     return(new GetRoleOutput
     {
         Role = _roleService.GetRole(input.RoleId)
     });
 }
예제 #3
0
        public GetRoleOutput GetRole(GetRoleInput input)
        {
            var Role =
                _RoleRepository
                .GetAll()
                .Include(q => q.CreatorUser)
                .Include(q => q.Answers)
                .Include("Answers.CreatorUser")
                .FirstOrDefault(q => q.Id == input.Id);

            if (Role == null)
            {
                throw new UserFriendlyException("There is no such a Role. Maybe it's deleted.");
            }

            if (input.IncrementViewCount)
            {
                Role.ViewCount++;
            }

            return(new GetRoleOutput
            {
                Role = Role.MapTo <RoleWithAnswersDto>()
            });
        }
예제 #4
0
        public IHttpActionResult GetRole(GetRoleInput input)
        {
            Init();
            input.AccessToken = ApiSession.AccessToken;
            GetRoleOutput output = _rolesSvc.GetRole(input);

            return(Ok(output));
        }
        public async Task <JsonResult> Load(GetRoleInput input)
        {
            var result = await _roleService.GetPagedAsync(input);

            return(Json(new
            {
                total = result.TotalCount,
                rows = result.Items
            }));
        }
예제 #6
0
        public Page <GetRoleOutput> GetRoleList(GetRoleInput input)
        {
            var result = _roleRepository.GetAll().Where(t => t.Status == SysStatus.效)
                         .WhereIf(!string.IsNullOrEmpty(input.Name), t => t.Name.Contains(input.Name) || t.Code.Contains(input.Name))
                         .Include(u => u.RoleMenuList);
            var pageResult = result.PageAndOrderBy(input);
            var output     = new List <GetRoleOutput>();

            foreach (var r in pageResult)
            {
                var userOutput = ObjectMapper.Map <GetRoleOutput>(r);
                foreach (var rm in r.RoleMenuList)
                {
                    userOutput.MenuIds.Add(rm.MenuId);
                }
                output.Add(userOutput);
            }
            return(new Page <GetRoleOutput>(input, result.Count(), output));
        }
예제 #7
0
        public GetRoleOutput GetRole(GetRoleInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/roles/getRole", RestSharp.Method.POST);
                req.AddHeader("Content-Type", "application/json");
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddJsonBody(input);
                GetRoleOutput response = http.HttpPost <GetRoleOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("GetRole : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
예제 #8
0
        /// <summary>
        /// 根据查询条件获取角色分页列表
        /// </summary>
        public async Task <PagedResultDto <RoleDto> > GetPagedAsync(GetRoleInput input)
        {
            var maxWeight = await _roleManager.GetMaxWeightByUserIdAsync(AbpSession.UserId.Value);

            var query = _roleRepository.GetAll().Where(p => p.Weight <= maxWeight);

            //TODO:根据传入的参数添加过滤条件
            query = query.WhereIf(!input.RoleName.IsNullOrEmpty(),
                                  p => p.Name.Contains(input.RoleName) || p.DisplayName.Contains(input.RoleName));

            var roleCount = await query.CountAsync();

            var roles = await query
                        .OrderBy(input.Sorting)
                        .PageBy(input)
                        .ToListAsync();

            var roleDtos = roles.MapTo <List <RoleDto> >();

            return(new PagedResultDto <RoleDto>(
                       roleCount,
                       roleDtos
                       ));
        }
예제 #9
0
        public IActionResult GetRoleList([FromQuery] GetRoleInput input)
        {
            var roles = _roleService.GetRoleList(input);

            return(Ok(ResponseBody.From(roles)));
        }