public IActionResult Index(int[] humanId)
        {
            List <Human> human = null;

            if (humanId.Length > 0)
            {
                ViewData["HumanInfo"] = humanId.Length == 1 ? $"Single Human by the humanid= {humanId[0]}" : "Humans From Array";
                human = Repository.GetAllHumans().Where(x => humanId.Contains(x.Id)).ToList();
            }
            else
            {
                ViewData["HumanInfo"] = "All Humans";
                human = Repository.GetAllHumans().ToList();
            }
            return(View(human));
        }
Ejemplo n.º 2
0
        public IActionResult Index(int?humanId)
        {
            //соединяем с помощью Join, чтобы не делать несколько запросов к БД одновременно.
            //одновременно было 2 запроса, потому что для каждого человека выбиралось название страны и получалось что мы делали выборку людей и для каждого человека еще выборку названия страны
            IEnumerable <HumanIndexViewModel> humans =
                _humanRepository.GetAllHumans().Join(_countryRepository.GetAllCountries(),
                                                     human => human.CountryId,
                                                     country => country.Id,
                                                     (human, country) => new HumanIndexViewModel
            {
                Id          = human.Id,
                FirstName   = human.FirstName,
                LastName    = human.LastName,
                Age         = human.Age,
                CountryName = human.Country.Name,
                CountryId   = human.Country.Id
            });


            if (humanId == null)
            {
                return(View(humans));
            }
            else
            {
                return(View(humans.Where(human => human.Id == humanId)));
            }
        }
        public IActionResult Info()
        {
            var humans    = _humanRepository.GetAllHumans();
            var countries = _countryRepository.GetAllCountries();

            return(View(new HomeInfoViewModel {
                Humans = humans, Countries = countries
            }));
        }
Ejemplo n.º 4
0
        public IActionResult Info()
        {
            IEnumerable <Human>   humans    = _humanRepository.GetAllHumans();
            IEnumerable <Country> countries = _countryRepository.GetAllCountries();

            return(View(new HomeInfoViewModel {
                Humans = humans, Countries = countries
            }));
        }
Ejemplo n.º 5
0
        public IActionResult Index(int?humanId)
        {
            IEnumerable <HumanIndexViewModel> humans = _humanRepository.GetAllHumans().Select(
                human => new HumanIndexViewModel
            {
                Id          = human.Id,
                FirstName   = human.FirstName,
                LastName    = human.LastName,
                Age         = human.Age,
                CountryName = human.Country.Name
            });

            if (humanId != null)
            {
                humans = humans.Where(human => human.Id == humanId);
            }

            return(View(humans));
        }