private static void ClearOldReminders()
        {
            var reminders = ScheduledActionService.GetActions <Reminder>().ToArray();

            //delete reminders
            if (reminders.Length > 0)
            {
                foreach (var reminder in reminders)
                {
                    if (ScheduledActionService.Find(reminder.Name) != null)
                    {
                        ScheduledActionService.Remove(reminder.Name);
                    }

                    var friend = BirthdayUtility.GetFriendDetailsById(Convert.ToInt32(reminder.Name));

                    if (friend == null)
                    {
                        continue;
                    }

                    friend.IsReminderCreated = false;
                    BirthdayUtility.UpdateFriendDetails(friend);

                    //AppLog.writeToLog(DateTime.Now, reminder.Name + friend.UniqueId + friend.IsReminderCreated.ToString(), LogLevel.Error);
                }
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                if (NavigationContext.QueryString.TryGetValue(UriParameter.FriendId, out Parameter))
                {
                    Action       = ActionType.Details;
                    FriendEntity = BirthdayUtility.GetFriendDetailsById(Convert.ToInt32(Parameter));
                    DataContext  = FriendEntity;
                    var birthday = DateTime.Now;

                    BirthdayText.Text = FriendEntity.Birthday.HasValue
                        ? AppResources.BirthdayOnLabel + " : " + FriendEntity.Birthday.Value.ToString("dd MMM")
                        : AppResources.BirthdayOnLabel + " : " + AppResources.NotKnownLabel;


                    //update the UI based on the action
                    UpdateUIForAction(Action);

                    AutoEmailToggle.IsChecked = FriendEntity.SendAutoEmailOnBirthday;
                    AutoEmailToggle.Content   = (FriendEntity.SendAutoEmailOnBirthday) ? "Yes" : "No";

                    //format datetime to current culture
                    BirthdayPicker.Value = new DateTime(birthday.Year, birthday.Month, birthday.Day, CultureInfo.CurrentCulture.Calendar);

                    //add buttons to app bar
                    AddAppBarButtons(FriendEntity);
                }
                else
                {
                    Action = ActionType.Add;
                    ActivateSaveButton();
                }

                //remove backstack
                while (NavigationService.BackStack.Any() && !NavigationService.BackStack.ElementAt(0).Source.ToString().Contains("/MainPage.xaml"))
                {
                    NavigationService.RemoveBackEntry();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error On Navigation", MessageBoxButton.OK);
            }
        }
        /// <summary>
        /// Delete old calendar entries and add new ones
        /// </summary>
        public static void UpdateCalendarEntries()
        {
            try
            {
                ClearOldReminders();

                //add a dummy reminder to test in debug mode
//#if DEBUG

//                if (ScheduledActionService.Find("DummyReminder") != null)
//                {
//                    ScheduledActionService.Remove("DummyReminder");
//                }
//                Reminder dummyReminder = new Reminder("DummyReminder");
//                dummyReminder.BeginTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute + 1, 0);
//                dummyReminder.Title = AppResources.BirthdayLabel;
//                dummyReminder.Content = "Shahzad " + AppResources.BirthdayReminderMessage;
//                ScheduledActionService.Add(dummyReminder);

//#endif



                //create new reminders
                var allBirthdays = BirthdayUtility.GetBirthdays().AllBirthdays;

                if (allBirthdays == null || !allBirthdays.Any())
                {
                    return;
                }

                var orderedBirthdayList = allBirthdays.Where(b => b.DaysAhead.HasValue && b.DaysAhead > 0)
                                          .OrderBy(b => b.DaysAhead)
                                          .ToList();

                foreach (var birthday in orderedBirthdayList)
                {
                    //check to see if the reminder aleady exists and the birthday has a value
                    if (ScheduledActionService.Find(birthday.Id.ToString()) != null || !birthday.Birthday.HasValue)
                    {
                        continue;
                    }

                    //add a reminder
                    var birthdayValue = birthday.Birthday.Value;
                    var reminder      = new Reminder(birthday.Id.ToString())
                    {
                        BeginTime     = GetBeginTime(birthdayValue),
                        Content       = birthday.Name + " " + AppResources.BirthdayReminderMessage,
                        NavigationUri = new Uri("/FriendDetails.xaml?" + UriParameter.FriendId + "=" + birthday.Id, UriKind.Relative),
                        Title         = AppResources.BirthdayLabel
                    };

                    ScheduledActionService.Add(reminder);

                    //update friend details to reflect reminder created
                    var friend = BirthdayUtility.GetFriendDetailsById(birthday.Id);

                    if (friend == null)
                    {
                        continue;
                    }

                    friend.IsReminderCreated = true;
                    BirthdayUtility.UpdateFriendDetails(friend);
                }
            }
            catch (InvalidOperationException ex)
            {
                if (!ex.Message.Contains("The maximum number of ScheduledActions of this type have already been added"))
                {
                    throw;
                }
            }
        }
        private void SaveButtonClick(object sender, EventArgs e)
        {
            try
            {
                if (App.IsTrial)
                {
                    //messagebox to prompt to buy
                    var buyAppForSaveFriendMessageBox = new CustomMessageBox
                    {
                        Height             = 300,
                        Caption            = AppResources.BuyFullVersion,
                        Message            = AppResources.BuyAppForAddFriend,
                        LeftButtonContent  = AppResources.BuyLabel,
                        RightButtonContent = AppResources.LaterLabel,
                        VerticalAlignment  = VerticalAlignment.Center
                    };

                    buyAppForSaveFriendMessageBox.Dismissed += BuyAppForSaveFriendBoxDismissed;
                    buyAppForSaveFriendMessageBox.Show();

                    return;
                }
                if (String.IsNullOrEmpty(NameTextBox.Text) || !BirthdayPicker.Value.HasValue)
                {
                    MessageBox.Show(AppResources.WarnNameBdayCompulsory, AppResources.WarnDtlsReq, MessageBoxButton.OK);
                    return;
                }

                //display status message
                StatusText.Text           = AppResources.SavingFrndDtls;
                ContentStackPanel.Opacity = 0.2;
                StatusPanel.Visibility    = Visibility.Visible;
                int friendGuid;

                if (Action.Equals(ActionType.Add))
                {
                    friendGuid = AddNewFriend();
                    MessageBox.Show(AppResources.NewFrndCreatedMsg, AppResources.NewFrndAddedTitle, MessageBoxButton.OK);
                }
                else
                {
                    friendGuid = UpdateFriend();
                    MessageBox.Show(AppResources.FrndDtlsUpdated, AppResources.FrndDtlsUpdatedTitle, MessageBoxButton.OK);
                }

                //change the app bar buttons
                FriendEntity = BirthdayUtility.GetFriendDetailsById(friendGuid);
                AddAppBarButtons(FriendEntity);

                //remove focus from textbox
                RemoveFocus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, AppResources.ErrSavingFrndDtls, MessageBoxButton.OK);
            }
            finally
            {
                //hide status screen
                StatusPanel.Visibility    = Visibility.Collapsed;
                ContentStackPanel.Opacity = 1;
            }
        }