private IQueryable <GoodsDto> Query(Guid?id, GoodsQueryDto queryDto) { IQueryable <Goods> sourceDatas = _context.Goods; if (id != null) { Guid idv = id.Value; sourceDatas = sourceDatas.Where(x => x.Id == idv); } else if (queryDto != null) { DateTimeOffset now = DateTimeOffset.Now; sourceDatas = sourceDatas.Where(x => x.EndTime > now && x.StartTime <= now); if (queryDto.PriceMax != null) { sourceDatas = sourceDatas.Where(x => x.Price <= queryDto.PriceMax.Value); } if (queryDto.PriceMin != null) { sourceDatas = sourceDatas.Where(x => x.Price >= queryDto.PriceMin.Value); } if (queryDto.OrderingsIsNullOrEmpty()) { //sourceDatas = sourceDatas.OrderByDescending(x => x.CreateTime); } } var datas = from d in sourceDatas select new GoodsDto { Id = d.Id, Name = d.Name, Pricing = d.Pricing, Words = d.Words, Days = d.Days, InitPrice = d.InitPrice, Price = d.Price, CurrencySymbol = d.CurrencySymbol, Currency = d.Currency, Description = d.Description, CreateTime = d.CreateTime, StartTime = d.StartTime, EndTime = d.EndTime, }; Expression <Func <GoodsDto, double> > exp = _ => _.Price; //datas = Queryable.OrderByDescending(datas, exp); //datas = datas.OrderBy(x => x.Name).ThenBy(x => x.Price); //var datas = _mapper.ProjectTo<GoodsDto>(sourceDatas); return(datas); }
public async Task <PagedResult <GoodsDto> > GetGoodsAsync(GoodsQueryDto queryDto) { return(await Query(null, queryDto).ToPagedResultAsync(queryDto)); }