/// <summary>
 /// This method select current object from list and marked selected item.
 /// </summary>
 /// <param name="sender">object</param>
 /// <param name="e">SelectionChangedEventArgs</param>
 private void listBoxComponent_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (e.AddedItems.Count > 0)
     {
         var mySelectedItem = e.AddedItems[0] as ComponentItem;
         if (mySelectedItem != null)
         {
             itemComponentToDelete = mySelectedItem;
         }
     }
 }
        /// <summary>
        /// Method called after back from another page.
        /// </summary>
        /// <param name="e">NavigationEventArgs</param>
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            // Call the base method.
            base.OnNavigatedTo(e);

            // Define the query to gather all of the to-do items.
            var ComponentItemInDB = from ViewModels.ComponentItem todo in ComponentDB.ComponentItems select todo;

            // Execute the query and place the results into a collection.
            ComponentItems = new ObservableCollection<ViewModels.ComponentItem>(ComponentItemInDB);

            // Create a strings for containing data about chosen component
            string component;

            // Try get value for component
            if (NavigationContext.QueryString.TryGetValue("component", out component))
            {
                if (component.Equals("listToDo"))
                  {
                      var firstOccurence = ComponentItems.Where(item => item.ItemName == "List to do");

                      if (firstOccurence.Count() == 0)
                      {
                          // Create a new to-do item based on the text box.
                          ViewModels.ComponentItem newComponent = new ViewModels.ComponentItem { ItemName = "List to do"};

                          // Add a to-do item to the observable collection.
                          ComponentItems.Add(newComponent);

                          // Add a component item to the local database
                          ComponentDB.ComponentItems.InsertOnSubmit(newComponent);
                      }
                }
                else if (component.Equals("aphorism"))
                {
                    var firstOccurence = ComponentItems.Where(item => item.ItemName == "Aphorism");

                    if (firstOccurence.Count() == 0)
                    {
                        // Create a new to-do item based on the text box.
                        ViewModels.ComponentItem newComponent = new ViewModels.ComponentItem { ItemName = "Aphorism" };

                        // Add a to-do item to the observable collection.
                        ComponentItems.Add(newComponent);

                        // Add a component item to the local database
                        ComponentDB.ComponentItems.InsertOnSubmit(newComponent);
                    }
                }
            }

            // Define the query to gather all of the time items.
            var TimeItemInDB = from ViewModels.TimeItem times in ComponentDB.TimeItems select times;

            // Execute the query and place the results into a collection.
            TimeItems = new ObservableCollection<ViewModels.TimeItem>(TimeItemInDB);

            // Save changes to the database.
            ComponentDB.SubmitChanges();

            // Checking if any element is in lists
            CheckAddedElements();
        }
        /// <summary>
        /// This method delete component from list and database.
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">RoutedEventArgs</param>
        private void DeleteComponent_Click(object sender, RoutedEventArgs e)
        {
            if (itemComponentToDelete != null)
            {

                ComponentItems.Remove(itemComponentToDelete);
                ComponentDB.ComponentItems.DeleteOnSubmit(itemComponentToDelete);

                // Set to null itemTimeToDelete
                itemComponentToDelete = null;

                // Save changes to the database.
                ComponentDB.SubmitChanges();

                // Checking if any element is in lists
                CheckAddedElements();
            }
        }
        /// <summary>
        /// Send information about chosen location to main page.
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">RoutedEventArgs</param>
        private void btnSaveLocation_Click(object sender, RoutedEventArgs e)
        {
            // Define the query to gather all of the to-do items.
            var ComponentItemInDB = from ViewModels.ComponentItem todo in ComponentDB.ComponentItems select todo;

            // Execute the query and place the results into a collection.
            ComponentItems = new ObservableCollection<ViewModels.ComponentItem>(ComponentItemInDB);

            // Finding existing element from database
            var firstOccurence = ComponentItems.Where(item => item.ItemName == "Weather");

            if (firstOccurence.Count() == 0)
            {

                // Create a new weather item based on the text box.
                ViewModels.ComponentItem newComponent = new ViewModels.ComponentItem { ItemName = "Weather", Data = tbxCity.Text + "," + tbxCountry.Text };

                // Add a weather item to the observable collection.
                ComponentItems.Add(newComponent);

                // Add a component item to the local database
                ComponentDB.ComponentItems.InsertOnSubmit(newComponent);

            }
            else
            {
                // Delete Old record from database.
                ComponentDB.ComponentItems.DeleteAllOnSubmit(firstOccurence);

                // Add new record to database.
                // Create a new weather item based on the text box.
                ViewModels.ComponentItem newComponent = new ViewModels.ComponentItem { ItemName = "Weather", Data = tbxCity.Text + "," + tbxCountry.Text };

                // Add a weather item to the observable collection.
                ComponentItems.Add(newComponent);

                // Add a component item to the local database
                ComponentDB.ComponentItems.InsertOnSubmit(newComponent);
            }

            // Save changes to the database.
            ComponentDB.SubmitChanges();

            // Navigate back to the main page.
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }