示例#1
0
        private static void AddFriend()
        {
            int Id = Int32.Parse(ReadStringFromInput("Your ID: "));

            PersonFound personFound = PersonService.GetById(Id);

            if (!personFound.Found)
            {
                Console.WriteLine("ID does not exists.");
                return;
            }

            int FriendId = Int32.Parse(ReadStringFromInput("Friend ID: "));

            if (FriendId == Id)
            {
                Console.WriteLine("You can not add yourself as friend.");
                return;
            }

            PersonFound friendFound = PersonService.GetById(FriendId);

            if (!friendFound.Found)
            {
                Console.WriteLine("ID does not exists.");
                return;
            }

            if (personFound.Person.Friends.Exists(person => person.personId == personFound.Person.Id && person.friendId == friendFound.Person.Id))
            {
                Console.WriteLine("This person is already your friend.");
                return;
            }

            PersonService.AddPersonFriend(personFound.Person.Id, friendFound.Person.Id);
        }