public async Task <PagedResultDto <SemesterDto> > Query(SemesterQueryInput input) { //验证参数 if (!input.PageSize.HasValue) { throw new UserFriendlyException("传入PageSize参数不正确!"); } if (!input.Start.HasValue) { throw new UserFriendlyException("传入Start参数不正确!"); } //获取总数 var totalcount = await _semesterRepository.CountAsync(); //获取查询对象 var query = _semesterRepository.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 <SemesterDto>(totalcount, courses.MapTo <List <SemesterDto> >())); }
public async Task <SemesterSimpleDto> Simple(SemesterQueryInput input) { //检查传入参数 if (!input.Id.HasValue) { throw new UserFriendlyException("传入Id参数不正确!"); } var result = await _semesterRepository.FirstOrDefaultAsync(x => x.Id == input.Id.Value); if (result == null) { throw new UserFriendlyException("该条信息不存在!"); } return(result.MapTo <SemesterSimpleDto>()); }