コード例 #1
0
ファイル: ShelterLogic.cs プロジェクト: yszilagyi/Shelter
        public bool SendAnimalToShelter(Animal animal, Person person)
        {
            if (person.OwnedAnimals.Count == 0)
            {
                throw new Exception("You don't have any animals to send to shelter.");
            }
            else
            {
                if (!d.ContainsValue(animal.GetType()))
                {
                    throw new Exception("Wrong kind of animal!");
                }
                else if (person.OwnedAnimals.TryGetValue(animal.Name, out animal))
                {
                    Console.WriteLine($"{person.Name} is sending {animal.Name} to Shelter.");
                    _shelterRepository.AddAnimal(animal);
                    person.OwnedAnimals.Remove(animal.Name);
                }
                else

                {
                    throw new Exception("Something went wrong");
                }

                return(true);
            }
        }