Example #1
0
        public IActionResult Index()
        {
            List <AuthorListingViewModel> model = new List <AuthorListingViewModel>();

            repoAuthor.GetAll().ToList().ForEach(a =>
            {
                AuthorListingViewModel author = new AuthorListingViewModel
                {
                    Id    = a.Id,
                    Name  = $"{a.FirstName} {a.LastName}",
                    Email = a.Email
                };
                author.TotalBooks = repoBook.GetAll().Count(x => x.AuthorId == a.Id);
                model.Add(author);
            });
            return(View(model));
        }
        public IActionResult Index()
        {
            List <AuthorListingViewModel> model = new List <AuthorListingViewModel>();

            _repoAuthor.GetAllData().ToList().ForEach(a =>
            {
                AuthorListingViewModel author = new AuthorListingViewModel
                {
                    Id    = a.Id,
                    Name  = $"{a.FirstName} {a.LastName}",
                    Email = a.Email
                };
                //aqui me busca el total de los libros de ese author
                author.TotalBook = _repoBook.GetAllData().Count(x => x.AuthorId == a.Id);
                //aqui se agrega a el model view de listing para la vista
                model.Add(author);
            });
            return(View("Index", model));
        }