Exemple #1
0
        public IActionResult _CategoriasBusca(string json)
        {
            JObject o = JObject.Parse(json);

            FiltrosCategoriasModel f = o.ToObject <FiltrosCategoriasModel>();

            IEnumerable <CategoriaLivro> ctgs = _facade.Listar <CategoriaLivro>();

            ctgs = f.Id != 0 ? ctgs.Where(t => t.Id == f.Id) : ctgs;

            ctgs = !string.IsNullOrEmpty(f.Nome) ?
                   ctgs.Where(c => c.Nome.Contains(f.Nome)) : ctgs;

            ctgs = f.IncluiInativados ?
                   ctgs : ctgs.Where(l => !l.Inativo);

            ctgs = f.PagAtual > 0 ? ctgs.Skip((f.PagAtual - 1) * 10) : ctgs;

            _vh = new ListaCategoriaLivroViewHelper
            {
                Entidades = new Dictionary <string, object>
                {
                    [typeof(IList <Livro>).FullName]            = ctgs.Take(10).ToList(),
                    [nameof(ListaCategoriaLivroModel.PagAtual)] = 1,
                    [nameof(ListaCategoriaLivroModel.PagMax)]   = (ctgs.Count() / 10) + 1
                }
            };

            ListaCategoriaLivroModel vm = (ListaCategoriaLivroModel)_vh.ViewModel;

            vm.Filtros = f;

            return(PartialView("../Admin/PartialViews/_TabelaCategoriasConfigPartial", vm));
        }
Exemple #2
0
        protected override void ToViewModel()
        {
            ListaCategoriaLivroModel vm = new ListaCategoriaLivroModel
            {
                PagAtual = (int)Entidades[nameof(ListaCategoriaLivroModel.PagAtual)],
                PagMax   = (int)Entidades[nameof(ListaCategoriaLivroModel.PagMax)]
            };

            IList <CategoriaLivro> categorias = (IList <CategoriaLivro>)Entidades[typeof(IList <CategoriaLivro>).FullName];

            CategoriaLivroViewHelper catVh = new CategoriaLivroViewHelper();

            foreach (var ctg in categorias)
            {
                catVh.Entidades = new Dictionary <string, object>
                {
                    [typeof(CategoriaLivro).Name] = ctg
                };
                vm.Categorias.Add((CategoriaLivroModel)catVh.ViewModel);
            }
            ;

            _viewModel = vm;
        }