Beispiel #1
0
        public ActionResult ListarMedicamentos(MedicamentoFiltroViewModel filtros)
        {
            var listaMedicamentos = medicamentos.GetAll()
                                    .Where(prop => (string.IsNullOrEmpty(filtros.NomeGenerico) || prop.NomeGenerico.Contains(filtros.NomeGenerico)) &&
                                           (string.IsNullOrEmpty(filtros.NomeFabrica) || prop.NomeFabrica.Contains(filtros.NomeFabrica)) &&
                                           (string.IsNullOrEmpty(filtros.NomeFabricante) || prop.NomeFabricante.Contains(filtros.NomeFabricante)))
                                    .OrderBy(prop => prop.Id);

            ViewBag.RouteValues = filtros.RouteValues;

            if (listaMedicamentos.Count() == 0)
            {
                return(PartialView("_GridSemRegistros"));
            }

            return(PartialView("_ListarMedicamento", listaMedicamentos.ToPagedList(filtros.Pagina, ViewModelBase.NUMERO_ITENS_PAGINA)));
        }
        public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page)
        {
            ViewBag.CurrentSort = sortOrder;
            ViewBag.NomeParam   = String.IsNullOrEmpty(sortOrder) ? "Nome_desc" : "";


            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            var medicamentos = from m in repoMedicamento.GetAll().ToList()
                               select m;

            if (!String.IsNullOrEmpty(searchString))
            {
                medicamentos = medicamentos.Where(s => s.Nome.ToUpper().Contains(searchString.ToUpper()));
            }

            switch (sortOrder)
            {
            case "Nome_Desc":
                medicamentos = medicamentos.OrderByDescending(x => x.Nome);
                break;

            default:
                medicamentos = medicamentos.OrderByDescending(x => x.Id);
                break;
            }

            int pageSize   = 20;
            int pageNumber = (page ?? 1);

            return(View(medicamentos.ToPagedList(pageNumber, pageSize)));
        }