Ejemplo n.º 1
0
        public async Task <TeacherCourseDto> Get(TeacherCourseQueryInput input)
        {
            //检查传入参数
            if (!input.Id.HasValue)
            {
                throw new UserFriendlyException("传入Id参数不正确!");
            }

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

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

            return(result.MapTo <TeacherCourseDto>());
        }
Ejemplo n.º 2
0
        public async Task <PagedResultDto <TeacherCourseDto> > Query(TeacherCourseQueryInput input)
        {
            //验证参数
            if (!input.PageSize.HasValue)
            {
                throw new UserFriendlyException("传入PageSize参数不正确!");
            }
            if (!input.Start.HasValue)
            {
                throw new UserFriendlyException("传入Start参数不正确!");
            }


            //获取查询对象
            var query = _teacherCourseRepository.GetAll();

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

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

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

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

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

            //包装为分页输出对象
            return(new PagedResultOutput <TeacherCourseDto>(totalcount, courses.MapTo <List <TeacherCourseDto> >()));
        }