public async Task <SubjectProjectSimpleDto> Simple(SubjectProjectQueryInput input) { //检查传入参数 if (!input.Id.HasValue) { throw new UserFriendlyException("传入Id参数不正确!"); } var result = await _subjectProjectRepository.FirstOrDefaultAsync(x => x.Id == input.Id.Value); if (result == null) { throw new UserFriendlyException("该条信息不存在!"); } return(result.MapTo <SubjectProjectSimpleDto>()); }
public async Task <PagedResultDto <SubjectProjectDto> > Query(SubjectProjectQueryInput input) { //验证参数 if (!input.PageSize.HasValue) { throw new UserFriendlyException("传入PageSize参数不正确!"); } if (!input.Start.HasValue) { throw new UserFriendlyException("传入Start参数不正确!"); } //获取总数 var totalcount = await _subjectProjectRepository.CountAsync(); //获取查询对象 var query = _subjectProjectRepository.GetAll(); //添加关键词条件 if (!string.IsNullOrEmpty(input.KeyWord)) { query = query.Where(x => x.Name.Contains(input.KeyWord) ); } //添加所属学期条件 if (input.SemesterId.HasValue) { query = query.Where(x => x.SemesterId == input.SemesterId.Value); } //添加分页条件 query = query.OrderBy(x => x.CreationTime) .Skip(input.Start.Value).Take(input.PageSize.Value); //执行查询 var subjectProjects = await Task.FromResult(query.ToList()); //包装为分页输出对象 return(new PagedResultOutput <SubjectProjectDto>(totalcount, subjectProjects.MapTo <List <SubjectProjectDto> >())); }