示例#1
0
        public IActionResult GetParents([FromQuery] ParentQueryParameters parentQuery)
        {
            if (!typeCheckerHelper.CheckIfTypeHasPoperties(parentQuery.Fields, typeof(ParentDto)))
            {
                return(BadRequest());
            }

            var parentsFromRepo = parentRepo.GetParent(parentQuery);

            IEnumerable <ParentDto> cl = Mapper.Map <IEnumerable <ParentDto> >(parentsFromRepo);

            return(Ok(cl.ShapeData(parentQuery.Fields)));
        }
示例#2
0
        public PagedList <Parents> GetParent(ParentQueryParameters prParam)
        {
            var collection = context.Parents.AsQueryable();

            if (!string.IsNullOrWhiteSpace(prParam.Id) && int.TryParse(prParam.Id, out var intId))
            {
                collection = collection.Where(pr => pr.ParentId == intId);
            }

            if (!string.IsNullOrWhiteSpace(prParam.LastName))
            {
                collection = collection.Where(pr => pr.LastName.Contains(prParam.LastName, StringComparison.OrdinalIgnoreCase));
            }

            if (!string.IsNullOrWhiteSpace(prParam.FirstName))
            {
                collection = collection.Where(pr => pr.FirstName.Contains(prParam.FirstName, StringComparison.OrdinalIgnoreCase));
            }

            if (!string.IsNullOrWhiteSpace(prParam.PhoneNumber))
            {
                collection = collection.Where(pr => pr.PhoneNumber.Contains(prParam.PhoneNumber, StringComparison.OrdinalIgnoreCase));
            }

            if (!string.IsNullOrWhiteSpace(prParam.Email))
            {
                collection = collection.Where(pr => pr.Email.Contains(prParam.Email, StringComparison.OrdinalIgnoreCase));
            }

            if (!string.IsNullOrWhiteSpace(prParam.City))
            {
                collection = collection.Where(pr => pr.City.Contains(prParam.City, StringComparison.OrdinalIgnoreCase));
            }

            if (!string.IsNullOrWhiteSpace(prParam.Adress))
            {
                collection = collection.Where(pr => pr.Adress.Contains(prParam.Adress, StringComparison.OrdinalIgnoreCase));
            }

            collection = ReflectionHelper.PerformSorting <Parents>(prParam.OrderBy, collection);

            return(PagedList <Parents> .Create(collection, prParam.PageNumber, prParam.PageSize));
        }