public async Task <PagedResultDto <TeacherDto> > Query(TeacherQueryInput input) { //验证参数 if (!input.PageSize.HasValue) { throw new UserFriendlyException("传入PageSize参数不正确!"); } if (!input.Start.HasValue) { throw new UserFriendlyException("传入Start参数不正确!"); } //获取总数 var totalcount = await _teacherRepository.CountAsync(); //获取查询对象 var query = _teacherRepository.GetAll(); //添加分页条件 query = query.OrderBy(x => x.CreationTime) .Skip(input.Start.Value).Take(input.PageSize.Value); //执行查询 var courses = await Task.FromResult(query.ToList()); //包装为分页输出对象 return(new PagedResultOutput <TeacherDto>(totalcount, courses.MapTo <List <TeacherDto> >())); }
public async Task <TeacherSimpleDto> Simple(TeacherQueryInput input) { //检查传入参数 if (!input.Id.HasValue) { throw new UserFriendlyException("传入Id参数不正确!"); } var result = await _teacherRepository.FirstOrDefaultAsync(x => x.Id == input.Id.Value); if (result == null) { throw new UserFriendlyException("该条信息不存在!"); } return(result.MapTo <TeacherSimpleDto>()); }