Example #1
0
        public async Task <CourseSimpleDto> Simple(CourseQueryInput input)
        {
            //检查传入参数
            if (!input.Id.HasValue)
            {
                throw new UserFriendlyException("传入Id参数不正确!");
            }

            var result = await _courseRepository.FirstOrDefaultAsync(x => x.Id == input.Id.Value);

            if (result == null)
            {
                throw new UserFriendlyException("该条信息不存在!");
            }

            return(result.MapTo <CourseSimpleDto>());
        }
Example #2
0
        public async Task <PagedResultDto <CourseDto> > Query(CourseQueryInput input)
        {
            //验证参数
            if (!input.PageSize.HasValue)
            {
                throw new UserFriendlyException("传入PageSize参数不正确!");
            }
            if (!input.Start.HasValue)
            {
                throw new UserFriendlyException("传入Start参数不正确!");
            }

            //获取查询对象
            var query = _courseRepository.GetAll().Where(
                x => !x.SubjectProject.IsDeleted &&
                !x.SubjectProject.Semester.IsDeleted
                );

            //添加关键词条件
            if (!string.IsNullOrEmpty(input.KeyWord))
            {
                query = query.Where(x =>
                                    x.Name.Contains(input.KeyWord)
                                    );
            }

            //添加所属项目条件
            if (input.SubjectProjectId.HasValue)
            {
                query = query.Where(x => x.SubjectProjectId == input.SubjectProjectId.Value);
            }

            //获取总数
            var totalcount = await Task.FromResult(query.Count());

            //添加分页条件
            query = query.OrderBy(x => x.CreationTime)
                    .Skip(input.Start.Value).Take(input.PageSize.Value);

            //执行查询
            var courses = await Task.FromResult(query.ToList());

            //包装为分页输出对象
            return(new PagedResultOutput <CourseDto>(totalcount, courses.MapTo <List <CourseDto> >()));
        }
        public async Task <PagedResultDto <CourseListDto> > GetPaged([FromBody] CourseQueryInput input)
        {
            var query = _courseManager.QueryAsNoTracking
                        .Where(input.QueryConditions);


            var count = await query.CountAsync();


            var entityList = await query.OrderBy(input.SortConditions)
                             .PageBy(input)
                             .ToListAsync();

            var dtoList = ObjectMapper.Map <IReadOnlyList <CourseListDto> >(entityList);


            return(new PagedResultDto <CourseListDto>(count, dtoList));
        }