Exemplo n.º 1
0
        public virtual async Task <AppPagedResultOutput <SoftUserLoginListDto> > GetLoginPageList(GetPageListInput input)
        {
            var query = _softUserLoginRepository.GetAll();

            var where = FilterExpression.FindByGroup <SoftUserLogin>(input.Filter);


            var queryCount = query.Where(where)
                             .GroupJoin(_softUserRepository.GetAll(), left => left.SoftUserId, right => right.Id,
                                        (left, right) => new
            {
                UserLicense = left,
                SoftUser    = right
            })
                             .GroupJoin(_softRepository.GetAll(), left => left.UserLicense.SoftId, right => right.Id,
                                        (left, right) => new
            {
                SoftUserLicense = left.UserLicense,
                SoftUser        = left.SoftUser,
                Soft            = right
            });

            if (FilterExpression.HasValue(input.Filter, "loginName"))
            {
                string value = FilterExpression.GetValue(input.Filter, "loginName");
                queryCount = queryCount.Where(t => t.SoftUser.FirstOrDefault().LoginName.Contains(value));
            }

            if (FilterExpression.HasValue(input.Filter, "softName"))
            {
                string value = FilterExpression.GetValue(input.Filter, "softName");
                queryCount = queryCount.Where(t => t.Soft.FirstOrDefault().Name.Contains(value));
            }

            int count = await queryCount.CountAsync();


            var queryList = query.Where(where)
                            .GroupJoin(_softUserRepository.GetAll(), left => left.SoftUserId, right => right.Id,
                                       (left, right) => new
            {
                SoftUserLogin = left,
                SoftUser      = right
            })
                            .GroupJoin(_softRepository.GetAll(), left => left.SoftUserLogin.SoftId, right => right.Id,
                                       (left, right) => new
            {
                SoftUserLogin = left.SoftUserLogin,
                SoftUser      = left.SoftUser,
                Soft          = right
            });

            if (FilterExpression.HasValue(input.Filter, "loginName"))
            {
                string value = FilterExpression.GetValue(input.Filter, "loginName");
                queryList = queryList.Where(t => t.SoftUser.FirstOrDefault().LoginName.Contains(value));
            }

            if (FilterExpression.HasValue(input.Filter, "softName"))
            {
                string value = FilterExpression.GetValue(input.Filter, "softName");
                queryList = queryList.Where(t => t.Soft.FirstOrDefault().Name.Contains(value));
            }


            queryList = queryList.OrderByDescending(t => t.SoftUserLogin.CreationTime)
                        .PageBy(input);
            var list = await queryList.Select(t => new SoftUserLoginListDto
            {
                Id           = t.SoftUserLogin.Id,
                Mcode        = t.SoftUserLogin.Mcode,
                Ip           = t.SoftUserLogin.Ip,
                CreationTime = t.SoftUserLogin.CreationTime,
                SoftName     = t.Soft.FirstOrDefault().Name,
                LoginName    = t.SoftUser.FirstOrDefault().LoginName
            }).ToListAsync();

            var pageList = list;

            return(new AppPagedResultOutput <SoftUserLoginListDto>(count, pageList, input.CurrentPage, input.PageSize));
        }