private async Task SaveFriends()
        {
            try
            {
                var friendListTask = await DownloadFriends(App.AccessToken);

                friendListTask   = App.IsTrial ? friendListTask.Take(100).ToList() : friendListTask;
                _savedFriendList = BirthdayUtility.GetFriendList();

                if (!App.UserPreferences.ContactSync.FacebookSyncEnabled.HasValue || App.UserPreferences.ContactSync.FacebookSyncEnabled.Value)
                {
                    //display status message
                    StatusText.Text = AppResources.RetrievingFbFriend;
                    foreach (var user in friendListTask)
                    {
                        //check if the friend exists already
                        if (_savedFriendList != null && _savedFriendList.Count > 0 &&
                            _savedFriendList.Exists(f => !String.IsNullOrEmpty(f.FacebookId) &&
                                                    f.FacebookId.Equals(user.FacebookId, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            UpdateExistingFriendToList(user, _savedFriendList.Find(x => !String.IsNullOrEmpty(x.FacebookId) &&
                                                                                   x.FacebookId.Equals(user.FacebookId, StringComparison.InvariantCultureIgnoreCase)));
                        }
                        else
                        {
                            BirthdayUtility.AddNewFriend(user);
                        }
                    }
                }

                //Save friend list to file
                StatusText.Text = AppResources.SaveBdays;

                //update the reminder list
                StatusText.Text = AppResources.CreateBdayReminder;
                ReminderUtility.UpdateCalendarEntries();
                //BirthdayUtility.downloadProfileImages(isSync);

                //update last sync time in settings and app user preferences
                App.UserPreferences.ContactSync.LastSync = DateTime.Now;
                if (App.UserPreferences != null)
                {
                    SettingsUtility.UpdateUserSettings(App.UserPreferences);
                }

                await BirthdayUtility.SyncCards(App.UserPreferences.UserDetails.FacebookId);

                //update card sync status
                App.UserPreferences.ContactSync.CardsSynced = true;
                if (App.UserPreferences != null)
                {
                    SettingsUtility.UpdateUserSettings(App.UserPreferences);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, AppResources.ErrBuildBdayList, MessageBoxButton.OK);
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
        }
        private int AddNewFriend()
        {
            //gather friend details
            var friendDetails = new FriendEntity
            {
                Name     = NameTextBox.Text,
                Birthday =
                    (BirthdayPicker.Value.HasValue)
                        ? BirthdayPicker.Value.Value
                        : new DateTime?(),
                Email                   = EmailTextBox.Text,
                PhoneNumber             = ContactTextBox.Text,
                SendAutoEmailOnBirthday = AutoEmailToggle.IsChecked != null && AutoEmailToggle.IsChecked.Value,
                ProfilePictureUrl       = Constants.DefaultProfilePic,
                TypeOfContact           = ContactType.Custom
            };

            //write updated details to db
            return(BirthdayUtility.AddNewFriend(friendDetails));
        }