private void InsertFriend(Friend friend)
 {
   var friends = ReadFromFile();
   var maxFriendId = friends.Count == 0 ? 0 : friends.Max(f => f.Id);
   friend.Id = maxFriendId + 1;
   friends.Add(friend);
   SaveToFile(friends);
 }
 private void UpdateFriend(Friend friend)
 {
   var friends = ReadFromFile();
   var existing = friends.Single(f => f.Id == friend.Id);
   var indexOfExisting = friends.IndexOf(existing);
   friends.Insert(indexOfExisting, friend);
   friends.Remove(existing);
   SaveToFile(friends);
 }
 public void SaveFriend(Friend friend)
 {
   if (friend.Id <= 0)
   {
     InsertFriend(friend);
   }
   else
   {
     UpdateFriend(friend);
   }
 }