private IList <SwapItem> GetItemsFromAmazonSwapDB()
 {
     using (var amazonSwapDbContext = new AmazonSwapDbContext())
     {
         return((from si in amazonSwapDbContext.SwapItems select si).ToList());
     }
 }
        private void ImportProductsInfo(IList <Product> products)
        {
            Console.WriteLine("Totale prodotti: " + products.Count);
            int index               = 0;
            int errors              = 0;
            int notFound            = 0;
            int globalIndex         = 0;
            var amazonSwapDbContext = new AmazonSwapDbContext();

            foreach (var product in products)
            {
                var currentItem = amazonSwapDbContext.SwapItems.FirstOrDefault(a => a.Ean == product.Ean);
                if (currentItem == null || (currentItem != null && (currentItem.Content == null || currentItem.Content == "error" || currentItem.Content == "none")))
                {
                    String json = GetInfoFromAmazonServices(product.Ean);

                    if (json == "error")
                    {
                        errors++;
                    }
                    if (json == "none")
                    {
                        notFound++;
                    }
                    if (currentItem != null)
                    {
                        currentItem.Content = json;
                    }
                    else
                    {
                        amazonSwapDbContext.SwapItems.Add(new SwapItem()
                        {
                            Ean = product.Ean, Content = json
                        });
                    }
                    // sleeps 1 second before next call
                    Thread.Sleep(400);
                }

                index++;
                globalIndex++;


                if (index == 100)
                {
                    index = 0;
                    amazonSwapDbContext.SaveChanges();
                    Console.WriteLine("Prodotti elaborati: " + globalIndex);
                }
            }
            amazonSwapDbContext.SaveChanges();

            Console.WriteLine("Prodotti elaborati: " + globalIndex);
            Console.WriteLine("Prodotti non trovati: " + notFound);
            Console.WriteLine("Errori riscontrati: " + errors);
        }