Esempio n. 1
0
        private void Item_Clicked(object sender, RoutedEventArgs e)
        {
            /*Category kategorie = new Category();
             * kategorie = sender as Category;*/
            var grid = sender as Grid;

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

            if (InternetConnection == true)
            {
                Category selectedItem = ListBoxCategories.SelectedItem as Category;
                this.NavigationService.Navigate(new CategoryPage(selectedItem));
            }
            else
            {
                CategoryLocal selectedItem = ListBoxCategories.SelectedItem as CategoryLocal;
                Category      kategorie    = new Category();
                kategorie.Id          = selectedItem.Id;
                kategorie.Name        = selectedItem.Name;
                kategorie.Image_path  = selectedItem.Image_path;
                kategorie.Description = selectedItem.Description;
                this.NavigationService.Navigate(new CategoryPage(kategorie));
            }
        }
Esempio n. 2
0
        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);
        }