示例#1
0
        public PagedList <Subjects> GetSubjects(SubjectQueryParameters sParam)
        {
            var collection = context.Subjects.AsQueryable();

            if (!string.IsNullOrWhiteSpace(sParam.SubjectID) && int.TryParse(sParam.SubjectID, out var intId))
            {
                collection = collection.Where(sb => sb.SubjectId == intId);
            }

            if (!string.IsNullOrWhiteSpace(sParam.Name))
            {
                collection = collection.Where(sb => sb.Name.Contains(sParam.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (!string.IsNullOrWhiteSpace(sParam.ShortName))
            {
                collection = collection.Where(sb => sb.ShortName.Contains(sParam.ShortName, StringComparison.OrdinalIgnoreCase));
            }

            if (!string.IsNullOrWhiteSpace(sParam.Description))
            {
                collection = collection.Where(sb => sb.Description.Contains(sParam.Description, StringComparison.OrdinalIgnoreCase));
            }

            collection = ReflectionHelper.PerformSorting <Subjects>(sParam.OrderBy, collection);

            return(PagedList <Subjects> .Create(collection, sParam.PageNumber, sParam.PageSize));
        }
示例#2
0
        public IActionResult GetSubjects([FromQuery] SubjectQueryParameters subjects)
        {
            if (!typeCheckerHelper.CheckIfTypeHasPoperties(subjects.Fields, typeof(SubjectDto)))
            {
                return(BadRequest());
            }

            var subjectsFromRepo = subjectRepository.GetSubjects(subjects);

            IEnumerable <SubjectDto> sb = Mapper.Map <IEnumerable <SubjectDto> >(subjectsFromRepo);

            return(Ok(sb.ShapeData(subjects.Fields)));
        }