コード例 #1
0
        public IActionResult GetCountryById(int countryId)
        {
            var country = _countryRepository.GetCountryById(countryId);

            //country = null;
            if (country == null)
            {
                ModelState.AddModelError("", "Error getting a country");
                ViewBag.Message = $"There was a problem retrieving country with id {countryId} " +
                                  $"from the database or no country with that id exists";
                country = new CountryDto();
            }

            var authors = _countryRepository.GetAuthorsFromACountry(countryId);

            if (authors.Count() <= 0)
            {
                ViewBag.AuthorMessage = $"There are no authors from country with id {country.Id}";
            }

            var countryAuthorsViewModel = new CountryAuthorsViewModel
            {
                Country = country,
                Authors = authors
            };

            ViewBag.SuccessMessage = TempData["SuccessMessage"];
            return(View(countryAuthorsViewModel));
        }
コード例 #2
0
        public IActionResult Detail(int countryId)
        {
            var country = countryRepository.GetCountryById(countryId);

            if (country == null)
            {
                ModelState.AddModelError("", "Error getting a country");
                ViewBag.Message = $"There was a problem retrieving country id {countryId}" +
                                  $" from the database or no country with id exists.";

                country = new CountryDto();
            }

            var authors = countryRepository.GetAuthorFromCountry(countryId);

            if (authors.Count() <= 0)
            {
                ViewBag.AuthorMessage = $"There was a problem retrieving authors in country id {countryId}" +
                                        $" from the database or no authors with country id exists.";
            }

            CountryAuthorsViewModel countryAuthors = new CountryAuthorsViewModel()
            {
                Country = country,
                Authors = authors
            };

            ViewBag.SuccessMessage = TempData["SuccessMessage"];
            return(View(countryAuthors));
        }