//查询Academy public async Task <IEnumerable <Academy> > GetAcademiesAsync(AcademyDtoParameters academyDtoParameters) { if (academyDtoParameters == null) { throw new ArgumentNullException(nameof(academyDtoParameters)); } //如果 筛选条件 和 查询字符串 都为空的话 if (string.IsNullOrWhiteSpace(academyDtoParameters.AcademyName) && string.IsNullOrWhiteSpace(academyDtoParameters.SearchTerm)) { return(await _context.Academies.ToListAsync()); } var academyItems = _context.Academies as IQueryable <Academy>; //筛选条件 if (!string.IsNullOrWhiteSpace(academyDtoParameters.AcademyName)) { academyDtoParameters.AcademyName = academyDtoParameters.AcademyName.Trim(); academyItems = academyItems.Where(x => x.AcademyName == academyDtoParameters.AcademyName); } //查询条件 if (!string.IsNullOrWhiteSpace(academyDtoParameters.SearchTerm)) { academyDtoParameters.SearchTerm = academyDtoParameters.SearchTerm.Trim(); academyItems = academyItems.Where(x => x.AcademyName.Contains(academyDtoParameters.SearchTerm) || x.AcademyCode.Contains(academyDtoParameters.SearchTerm)); } return(await academyItems.ToListAsync()); }
public async Task <ActionResult <IEnumerable <AcademyDto> > > GetAcademies([FromQuery] AcademyDtoParameters academyDtoParameters) { var academies = await _academyRepository.GetAcademiesAsync(academyDtoParameters); var academyDtos = _mapper.Map <IEnumerable <AcademyDto> >(academies); return(Ok(academyDtos)); }