public async Task <AccountInfoDto> GetInfo(long userid) { var user = await GetById(userid); if (user == null) { throw new UserNotFoundException(); } var roles = new List <SysRole>(); var permissions = new List <string>(); if (!string.IsNullOrEmpty(user.Roleid)) { var ids = SplitId(user.Roleid); foreach (var id in ids) { var role = await _roleService.GetById(id); if (role == null) { continue; } roles.Add(role); } permissions = await _unitOfWork.MenuRepository.GetPermissionsByRoleIds(ids); } var dept = await _deptService.GetById(user.Deptid.Value()); return(UserMapper.ToAccountInfoDto(user, dept, roles, permissions)); }
public ActionResult GetById([FromQuery] int id) { var Rs = _service.GetById(id); if (!Rs.status) { return(BadRequest("no data founded")); } return(Ok(Rs)); }
public async Task <PagedModel <RoleProfileDto> > GetPagedList(RoleSearchDto criteria) { Expression <Func <SysRole, bool> > condition = it => true; if (!string.IsNullOrWhiteSpace(criteria.RoleName)) { condition = condition.And(it => it.Name.Contains(criteria.RoleName) || it.Tips.Contains(criteria.RoleName)); } var result = await _unitOfWork.RoleRepository.PagedAsync( criteria.Page, criteria.Limit, condition, it => it.Id, true); var dto = RoleMapper.ToRoleProfileDto(result); if (dto.Count <= 0) { return(dto); } foreach (var item in dto.Data) { var dept = await _deptService.GetById(item.Deptid.Value()); item.DeptName = dept?.Simplename; if (!item.Pid.HasValue || item.Pid.Value == 0) { continue; } // 先从已有的列表里面获取,如果有就不再单独去取 if (dto.Data.Any(it => it.Id == item.Pid)) { item.PName = dto.Data.First(it => it.Id == item.Pid).Name; continue; } // 单独取 item.PName = (await GetById(item.Pid.Value))?.Name; } return(dto); }