Beispiel #1
0
        public async Task <IActionResult> ViewFanNameAndFavoritePlanet(string Url)
        {
            var fan = _fanService.GetMostRecentFan();

            var result = _fanService.CheckIfPlanetIsEntered(fan.Id, Url);

            if (result >= 1)
            {
                return(View("Error", new ErrorViewModel
                {
                    Message = "ERROR Planet is already saved as one of your favorties"
                }));
            }


            _fanService.AddFavoritePlanet(fan.Id, Url);
            var listofUrl = _fanService.FanFavPlanetUrl(fan.Id);

            var listOfPlanetNames = new List <PlanetsResponse>();

            foreach (var url in listofUrl.FanList) //validate add same planet here
            {
                var planetName = new PlanetsResponse();
                planetName = await _mapPlanet.ListOfFanFavPlanets(url.Url);

                listOfPlanetNames.Add(planetName);
            }
            var listOfPlanetNamesAndFanName = new FanAndFavoritePlanetViewModel();

            listOfPlanetNamesAndFanName.ListOfPlanets = listOfPlanetNames;
            listOfPlanetNamesAndFanName.Name          = fan.Name;

            return(View(listOfPlanetNamesAndFanName));
        }