Example #1
0
        private void CommitToDatabase(List <AsinProductData> asinData)
        {
            using (var db = new CheapeesEntities())
            {
                db.Configuration.AutoDetectChangesEnabled = false;
                db.Configuration.ValidateOnSaveEnabled    = false;

                for (int i = 0; i < asinData.Count; i++)
                {
                    var           a       = asinData[i];
                    AmazonListing dbEntry = new AmazonListing();
                    dbEntry.Asin               = a.Asin;
                    dbEntry.BuyBox             = a.BuyBoxTotalPrice;
                    dbEntry.CurrentlyOwnBuyBox = a.CurrentlyOwnBuyBox;
                    dbEntry.Date               = DateTime.Now;
                    dbEntry.SalesRank          = a.SalesRankTopLevel;

                    if (db.AmazonListings.Where(o => o.Asin.Equals(dbEntry.Asin) && o.Date.Equals(dbEntry.Date)).Count() == 0 && db.AmazonListings.Local.Where(o => o.Asin.Equals(dbEntry.Asin) && o.Date.Equals(dbEntry.Date)).Count() == 0)
                    {
                        db.AmazonListings.Add(dbEntry);
                    }

                    if (i % 1000 == 0)
                    {
                        this.StatusDescription = string.Format("Committing to database - {0:0.00}% ({1}/{2})", i * 100.0 / asinData.Count, i, asinData.Count);
                        this.StatusPercentage  = i * 100 / asinData.Count;
                        db.SaveChanges();
                    }
                }

                db.SaveChanges();
            }
        }
    private void CommitToDatabase(List<AsinProductData> asinData)
    {
      using (var db = new CheapeesEntities())
      {
        db.Configuration.AutoDetectChangesEnabled = false;
        db.Configuration.ValidateOnSaveEnabled = false;

        for (int i = 0; i < asinData.Count; i++)
        {
          var a = asinData[i];
          AmazonListing dbEntry = new AmazonListing();
          dbEntry.Asin = a.Asin;
          dbEntry.BuyBox = a.BuyBoxTotalPrice;
          dbEntry.CurrentlyOwnBuyBox = a.CurrentlyOwnBuyBox;
          dbEntry.Date = DateTime.Now;
          dbEntry.SalesRank = a.SalesRankTopLevel;
          
          if (db.AmazonListings.Where(o => o.Asin.Equals(dbEntry.Asin) && o.Date.Equals(dbEntry.Date)).Count() == 0 && db.AmazonListings.Local.Where(o => o.Asin.Equals(dbEntry.Asin) && o.Date.Equals(dbEntry.Date)).Count() == 0)
          {
            db.AmazonListings.Add(dbEntry);
          }

          if (i % 1000 == 0)
          {
            this.StatusDescription = string.Format("Committing to database - {0:0.00}% ({1}/{2})", i * 100.0 / asinData.Count, i, asinData.Count);
            this.StatusPercentage = i * 100 / asinData.Count;
            db.SaveChanges();
          }

        }

        db.SaveChanges();
      }
    }