Beispiel #1
0
 public async Task <IEnumerable <Role> > GetListAsync(RoleOption option)
 {
     if (!string.IsNullOrWhiteSpace(option.Name))
     {
         return(await RoleRep.Find(o => o.Name.Contains(option.Name)).ToListAsync());
     }
     else
     {
         return(await RoleRep.Find(null).ToListAsync());
     }
 }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pageNumber"></param>
        /// <param name="rowsPrePage"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public async Task <PageResult <UserSunpleDto> > GetPageAsync(int pageNumber, int rowsPrePage, UserOption filter)
        {
            List <UserSunpleDto>       data = new List <UserSunpleDto>();
            PageResult <UserSunpleDto> list = new PageResult <UserSunpleDto>();
            string orderby   = " id desc";
            var    predicate = PredicateBuilder.True <User>();

            predicate = predicate.And(o => o.DeleteMark == null);
            if (!string.IsNullOrWhiteSpace(filter.Account))
            {
                predicate = predicate.And(o => o.Account == filter.Account);
            }
            if (!string.IsNullOrWhiteSpace(filter.RealName))
            {
                predicate = predicate.And(o => o.RealName == filter.RealName);
            }
            var tlist = await UserRep.Find(pageNumber, rowsPrePage, orderby, predicate).ToListAsync() ?? new List <User>();

            data = MapperHelper.MapList <User, UserSunpleDto>(tlist);
            List <long> roleIds = tlist.Select(o => o.RoleId).Distinct().ToList();

            if (roleIds.Count() > 0)
            {
                var roles = await RoleRep.Find(o => roleIds.Contains(o.Id)).ToListAsync();

                foreach (var d in data)
                {
                    var r = roles.FirstOrDefault(o => o.Id == d.RoleId);
                    d.RoleName = r?.Name;
                }
            }
            List <long?> DepartmentIds = tlist.Select(o => o.DepartmentId).Distinct().ToList();

            DepartmentIds.Remove(null);
            if (DepartmentIds.Count() > 0)
            {
                var Departments = await DepartmentRep.Find(o => DepartmentIds.Contains(o.Id)).ToListAsync();

                foreach (var d in data)
                {
                    var r = Departments.FirstOrDefault(o => o.Id == d.DepartmentId);
                    d.deptname = r?.Name;
                }
            }
            list.Data = data.ToList();
            int total = await UserRep.GetCountAsync(predicate);

            list.ItemCount = total;
            return(list);
        }
Beispiel #3
0
        public async Task <PageResult <Role> > GetPageAsync(int pageNumber, int rowsPrePage, RoleOption filter)
        {
            List <Role>       data    = new List <Role>();
            PageResult <Role> list    = new PageResult <Role>();
            string            orderby = " id desc";
            var predicate             = PredicateBuilder.True <Role>();

            if (!string.IsNullOrWhiteSpace(filter.Name))
            {
                predicate = predicate.And(o => o.Name.Contains(filter.Name));
            }
            var tlist = await RoleRep.Find(pageNumber, rowsPrePage, orderby, predicate).ToListAsync();

            list.Data = tlist.ToList();
            int total = await RoleRep.GetCountAsync(predicate);

            list.ItemCount = total;
            return(list);
        }