Exemple #1
0
        public async Task <PopularResult <byte[]> > GetBytesAsync(DriverQueryDto dto)
        {
            var result = new PopularResult <byte[]>();

            var queryAble = _driverRepository
                            .WhereIf(!dto.Name.IsNullOrWhiteSpace(), driver => driver.Name.Contains(dto.Name))
                            .WhereIf(dto.UnitId != 0, driver => driver.UnitId.Equals(dto.UnitId));

            var drivers = await AsyncExecuter.ToListAsync(queryAble);

            //转换为导出对象
            var dtos = ObjectMapper.Map <List <DriverEntity>, List <DriverDto> >(drivers);

            var stream = EPPlusHelper.GetMemoryStream(dtos);

            result.Success(stream.ToArray());

            return(result);
        }
Exemple #2
0
        public async Task <PopularResult <PagedResultDto <DriverDto> > > GetListAsync(DriverQueryDto dto)
        {
            var result = new PopularResult <PagedResultDto <DriverDto> >();

            var queryable = _driverRepository.Where(x => x.IsDelete == dto.IsDelete)
                            .WhereIf(!dto.Name.IsNullOrWhiteSpace(), driver => driver.Name.Contains(dto.Name))
                            .WhereIf(!dto.Name.IsNullOrWhiteSpace(), driver => driver.Name.Contains(dto.Name))
                            .WhereIf(dto.UnitId.HasValue, driver => driver.UnitId.Equals(dto.UnitId));

            var query = from v in queryable.PageBy(dto.SkipCount, dto.MaxResultCount)
                        join
                        u in _unitRepository.WhereIf(dto.UnitId.HasValue, unit => unit.Id == dto.UnitId)
                        on v.UnitId equals u.Id
                        into cls
                        from c in cls.DefaultIfEmpty()
                        join d in _dictRepository.Where(x => true) on v.ClassId equals d.Id
                        into f
                        from e in f.DefaultIfEmpty()
                        join cc in _dictRepository.Where(x => true) on v.StatusId equals cc.Id
                        into ee
                        from ff in ee.DefaultIfEmpty()
                        select new DriverEntity(v.Id)
            {
                Address        = v.Address,
                ClassId        = v.ClassId,
                FirstIssueDate = v.FirstIssueDate,
                Hiredate       = v.Hiredate,
                IdNo           = v.IdNo,
                Name           = v.Name,
                Sex            = v.Sex,
                StatusId       = v.StatusId,
                //IsDelete = v.IsDelete,
                CreateTime = v.CreateTime,
                Creator    = v.Creator,
                Remark     = v.Remark,
                UnitId     = v.UnitId,
                Unit       = c,
                Class      = e,
                Status     = ff
            };


            var drivers = await AsyncExecuter.ToListAsync(query.PageBy(dto.SkipCount, dto.MaxResultCount));

            var totalCount = await AsyncExecuter.CountAsync(queryable);

            var dtos = ObjectMapper.Map <List <DriverEntity>, List <DriverDto> >(drivers);

            result.Success(new PagedResultDto <DriverDto>(totalCount, dtos));
            return(result);
        }