コード例 #1
0
        public async Task <IActionResult> Categorias(int?id)
        {
            var categorias = await categoriaServices.BuscaPorTudo();

            var categotiaTRUE = Mapper.Map <IEnumerable <Categoria>, IEnumerable <CategoriaViewModel> >(categorias);

            if (id == null)
            {
                var buscaPost = categorias.FirstOrDefault();
                if (buscaPost != null)
                {
                    buscaPost.Posts.Where(p => p.PreviaTexto.Length > 200).ToList().ForEach(p => p.PreviaTexto = p.PreviaTexto.Substring(0, 200) + " ....");
                    var post = Mapper.Map <IEnumerable <Posts>, IEnumerable <PostsViewModel> >(buscaPost.Posts);
                    ViewBag.PostList = post;
                }
            }
            else
            {
                var buscaPost = await categoriaServices.BuscaPorId(Convert.ToInt32(id));

                buscaPost.Posts.Where(p => p.PreviaTexto.Length > 200).ToList().ForEach(p => p.PreviaTexto = p.PreviaTexto.Substring(0, 200) + " ....");
                var post = Mapper.Map <IEnumerable <Posts>, IEnumerable <PostsViewModel> >(buscaPost.Posts);

                ViewBag.PostList = post;
            }
            return(View(categotiaTRUE));
        }
コード例 #2
0
        public async Task <IActionResult> Post(int id)
        {
            var buscaPost = await postsServices.BuscaPorId(id);

            var post = Mapper.Map <Posts, PostsViewModel>(buscaPost);

            var categoria = await categoriaServices.BuscaPorId(buscaPost.Categoria.CategoriaId);

            categoria.Posts.Where(p => p.PreviaTexto.Length > 200).ToList().ForEach(p => p.PreviaTexto = p.PreviaTexto.Substring(0, 200) + " ....");
            ViewBag.PostsCategoria = Mapper.Map <IEnumerable <Posts>, IEnumerable <PostsViewModel> >(categoria.Posts);
            return(View(post));
        }