예제 #1
0
        public List <ContactoListViewModel> GetContactos(int?page, int?limit, string sortBy, string direction, string search, out int total)
        {
            var contactos = ContactoService.GetContactoFilter(search);

            total = contactos.Count();
            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize  = total;
            var records   = (from x in contactos
                             select new ContactoListViewModel
            {
                Id = x.Id,

                Nombre = x.Nombre,
                Domicilio = x.Domicilio,
                Telefono = x.Telefono,
                Email = x.Email,
                Constructora = x.Constructora.Nombre
            })
                            .AsQueryable();

            var totalPages = (int)Math.Ceiling((float)total / (float)total);

            direction = direction == null ? "ASC" : direction;

            if (direction.ToUpper() == "DESC")
            {
                records = records.OrderByDescending(s => s.Codigo);
                records = records.Skip(pageIndex * pageSize).Take(pageSize);
            }
            else
            {
                records = records.OrderBy(s => s.Codigo);
                records = records.Skip(pageIndex * pageSize).Take(pageSize);
            }

            return(records.ToList());
        }