Esempio n. 1
0
        private void AssignCatsToGender(List <Person> people)
        {
            var femaleOwned = new List <Pet>();
            var maleOwned   = new List <Pet>();

            foreach (var person in people.Where(p => p.Pets != null && p.PersonGender == Gender.Male))
            {
                maleOwned.AddRange(person.Pets.Where(p => p.PetType == PetType.Cat));
            }

            foreach (var person in people.Where(p => p.Pets != null && p.PersonGender == Gender.Female))
            {
                femaleOwned.AddRange(person.Pets.Where(p => p.PetType == PetType.Cat));
            }

            foreach (var pet in maleOwned.OrderBy(p => p.Name))
            {
                OwnedByMale.Add(pet);
            }

            foreach (var pet in femaleOwned.OrderBy(p => p.Name))
            {
                OwnedByFemale.Add(pet);
            }
        }
Esempio n. 2
0
        private async Task PerformQueryAsync()
        {
            try
            {
                IsSearching = true;

                OwnedByMale.Clear();
                OwnedByFemale.Clear();

                var people = await _jsonService.GetPeople();

                AssignCatsToGender(people);
            }
            catch (Exception ex)
            {
                // log it and show a friendly error message
            }
            finally
            {
                IsSearching = false;
            }
        }