Beispiel #1
0
        public paginacao <OrgaoDTO> List(
            int skip,
            int top,
            bool count,
            bool?soinativos = null,
            string pesquisa = null
            )
        {
            int?nCount = null;

            var orgaos = repository.List();

            if (soinativos == true)
            {
                orgaos = orgaos.Where(a => a.inativo != null);
            }
            else
            {
                orgaos = orgaos.Where(a => a.inativo == null);
            }

            if (pesquisa != null)
            {
                orgaos = orgaos.Where(a => a.idexterno.ToUpper().Contains(pesquisa.ToUpper()) || a.nome.ToUpper().Contains(pesquisa.ToUpper()));
            }

            if (count)
            {
                nCount = orgaos.Count();
            }

            if (skip < 0)
            {
                skip = 0;
            }
            orgaos = orgaos.OrderBy(a => a.nome);
            orgaos = orgaos.Skip(skip).Take(top);

            return(new paginacao <OrgaoDTO>()
            {
                values = orgaos.ProjectTo <OrgaoDTO>(mapper.ConfigurationProvider).ToArray(),
                count = nCount
            });
        }