Exemple #1
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            //gets the requested character
            string url    = (string)parameter;
            var    client = new GoTService();

            CurrentCharacter = await client.GetCharacterByUrlAsync(url);

            //First we need to check if the father data exists, if yes, the app makes a new call to the API to get the father's name
            if (CurrentCharacter.Father != "")
            {
                Character father = await client.GetCharacterByUrlAsync(CurrentCharacter.Father);

                FatherName = father.Name;
            }

            if (CurrentCharacter.Mother != "")
            {
                Character mother = await client.GetCharacterByUrlAsync(CurrentCharacter.Mother);

                MotherName = mother.Name;
            }

            if (CurrentCharacter.Spouse != "")
            {
                Character spouse = await client.GetCharacterByUrlAsync(CurrentCharacter.Spouse);

                SpouseName = spouse.Name;
            }

            foreach (var house in CurrentCharacter.Allegiances)
            {
                House h = await client.GetHouseByUrlAsync(house);

                //types are needed for navigation
                _allegiances.Add(h);
                //name is shown on the UI
                Allegiances.Add(h.Name);
            }

            foreach (var bookName in CurrentCharacter.Books)
            {
                Book b = await client.GetBookByUrlAsync(bookName);

                _books.Add(b);
                BookNames.Add(b.Name);
            }

            foreach (var povBookName in CurrentCharacter.PovBooks)
            {
                Book b = await client.GetBookByUrlAsync(povBookName);

                _povBooks.Add(b);
                PovBookNames.Add(b.Name);
            }

            await base.OnNavigatedToAsync(parameter, mode, state);
        }
        //Függvény, ami meghívódik, ha a CharacterDetailsPage lesz az aktív View
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            //Egy új service indítása, a paraméterben kapott karakter adatainak betöltése
            string     url     = (string)parameter;
            GoTService service = new GoTService();

            Character = await service.GetAsync <Character>(new Uri(url));

            if (!Character.Father.Equals(""))
            {
                var father = await service.GetAsync <Character>(new Uri(Character.Father));

                Father = father.Name;
            }

            if (!Character.Mother.Equals(""))
            {
                var mother = await service.GetAsync <Character>(new Uri(Character.Mother));

                Mother = mother.Name;
            }

            if (Character.Spouse.Length > 0)
            {
                var spouse = await service.GetAsync <Character>(new Uri(Character.Spouse));

                Spouse = spouse.Name;
            }

            if (!Character.Titles[0].Equals(""))
            {
                string titles = "";
                foreach (string title in Character.Titles)
                {
                    titles += title + ", ";
                }
                Titles = DeleteLastComa(titles);
            }

            if (!Character.Aliases[0].Equals(""))
            {
                string aliases = "";
                foreach (string alias in Character.Aliases)
                {
                    aliases += alias + ", ";
                }
                Aliases = DeleteLastComa(aliases);
            }

            if (Character.Books.Length > 0)
            {
                foreach (var bookURL in Character.Books)
                {
                    var book = await service.GetAsync <Book>(new Uri(bookURL));

                    this.BookArray.Add(book);
                }
            }
            else
            {
                BookArray.Add(new Book {
                    Name = "N/A"
                });
            }

            if (Character.PovBooks.Length > 0)
            {
                foreach (var povBookURL in Character.PovBooks)
                {
                    var povBook = await service.GetAsync <Book>(new Uri(povBookURL));

                    this.PovBookArray.Add(povBook);
                }
            }
            else
            {
                PovBookArray.Add(new Book {
                    Name = "N/A"
                });
            }

            if (Character.Allegiances.Length > 0)
            {
                foreach (var houseURL in Character.Allegiances)
                {
                    var house = await service.GetAsync <House>(new Uri(houseURL));

                    this.Allegiances.Add(house);
                }
            }
            else
            {
                Allegiances.Add(new House {
                    Name = "N/A"
                });
            }

            if (!Character.TvSeries[0].Equals(""))
            {
                string series = "";
                foreach (var season in Character.TvSeries)
                {
                    series += season + "\n";
                }
                TvSeries = series;
            }

            if (!Character.Playedby[0].Equals(""))
            {
                string playedBy = "";
                foreach (var actor in Character.Playedby)
                {
                    playedBy += actor + ", ";
                }
                PlayedBy = DeleteLastComa(playedBy);
            }

            await base.OnNavigatedToAsync(parameter, mode, state);
        }