private void Item_Clicked(object sender, RoutedEventArgs e)
        {
            var grid = sender as Grid;

            ListBoxItems.SelectedItem = grid.DataContext;
            bool InternetConnection = InternetAvailability.IsInternetAvailable();

            if (InternetConnection == true)
            {
                Item selectedItem = ListBoxItems.SelectedItem as Item;
                //MessageBox.Show(selectedItem.Name, "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                this.NavigationService.Navigate(new DetailPage(selectedItem));
            }
            else
            {
                ItemLocal selectedItem = ListBoxItems.SelectedItem as ItemLocal;
                Item      localitem    = new Item();
                localitem.Id          = selectedItem.Id;
                localitem.Name        = selectedItem.Name;
                localitem.Description = selectedItem.Description;
                localitem.Category_id = selectedItem.Category_id;
                localitem.Image_path  = selectedItem.Image_path;
                localitem.Price       = selectedItem.Price;
                localitem.Quantity    = selectedItem.Quantity;
                this.NavigationService.Navigate(new DetailPage(localitem));
            }
        }
        public async void Synchronize()
        {
            RestClient client = new RestClient(Shared.Url);

            var request = new RestRequest(Method.GET);

            request.AddParameter("Type", "get_categories");
            request.AddParameter("Data", "ahoj");
            var             response      = client.Execute <Input>(request);
            Input           responseInput = SimpleJson.DeserializeObject <Input>(response.Content);
            List <Category> categories    = SimpleJson.DeserializeObject <List <Category> >(responseInput.Data);
            //ListBoxCategories.ItemsSource = categories;
            await Database.Remake();

            List <CategoryLocal> localCategories = new List <CategoryLocal>();
            List <ItemLocal>     localItems      = new List <ItemLocal>();

            Directory.CreateDirectory("Images");
            foreach (Category kategorie in categories)
            {
                CategoryLocal kat = new CategoryLocal();
                kat.Id          = kategorie.Id;
                kat.Name        = kategorie.Name;
                kat.Description = kategorie.Description;
                kat.Image_path  = AppDomain.CurrentDomain.BaseDirectory + kategorie.Relative_Image_Path;
                WebClient client2 = new WebClient();
                client2.DownloadFile(kategorie.Image_path, kategorie.Relative_Image_Path);
                localCategories.Add(kat);

                var request2 = new RestRequest(Method.GET);
                request.AddParameter("Type", "get_items_by_category");
                request.AddParameter("Data", SimpleJson.SerializeObject(kategorie));
                var         response2      = client.Execute <Input>(request);
                Input       responseInput2 = SimpleJson.DeserializeObject <Input>(response2.Content);
                List <Item> items          = SimpleJson.DeserializeObject <List <Item> >(responseInput2.Data);
                foreach (Item item in items)
                {
                    ItemLocal itemlocal = new ItemLocal();
                    itemlocal.Id          = item.Id;
                    itemlocal.Name        = item.Name;
                    itemlocal.Category_id = kategorie.Id;
                    itemlocal.Description = item.Description;
                    itemlocal.Price       = item.Price;
                    itemlocal.Quantity    = item.Quantity;
                    itemlocal.Image_path  = AppDomain.CurrentDomain.BaseDirectory + item.Relative_Image_Path;
                    client2.DownloadFile(item.Image_path, item.Relative_Image_Path);
                    localItems.Add(itemlocal);
                }
            }
            await Database.SaveCategoriesAsync(localCategories);

            await Database.SaveItemsAsync(localItems);
        }