Пример #1
0
    private void CommitToDatabase(List<AsinPrepData> 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];
          if (db.AmazonPrepInstructions.Where(o => o.Asin.Equals(a.Asin)).Count() == 0 && db.AmazonPrepInstructions.Local.Where(o => o.Asin.Equals(a.Asin)).Count() == 0)
          {
            AmazonPrepInstruction dbEntry = new AmazonPrepInstruction();
            dbEntry.Asin = a.Asin;
            dbEntry.Labelling = a.Labelling;
            dbEntry.PrepRequired = a.Prep;

            db.AmazonPrepInstructions.Add(dbEntry);
          }
          else
          {
            AmazonPrepInstruction dbEntry = db.AmazonPrepInstructions.Where(o => o.Asin.Equals(a.Asin)).SingleOrDefault();
            if (dbEntry != null)
            {
              dbEntry.Labelling = a.Labelling;
              dbEntry.PrepRequired = a.Prep;
            }
          }

          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();
      }
    }
Пример #2
0
        private void CommitToDatabase(List <AsinPrepData> 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];
                    if (db.AmazonPrepInstructions.Where(o => o.Asin.Equals(a.Asin)).Count() == 0 && db.AmazonPrepInstructions.Local.Where(o => o.Asin.Equals(a.Asin)).Count() == 0)
                    {
                        AmazonPrepInstruction dbEntry = new AmazonPrepInstruction();
                        dbEntry.Asin         = a.Asin;
                        dbEntry.Labelling    = a.Labelling;
                        dbEntry.PrepRequired = a.Prep;

                        db.AmazonPrepInstructions.Add(dbEntry);
                    }
                    else
                    {
                        AmazonPrepInstruction dbEntry = db.AmazonPrepInstructions.Where(o => o.Asin.Equals(a.Asin)).SingleOrDefault();
                        if (dbEntry != null)
                        {
                            dbEntry.Labelling    = a.Labelling;
                            dbEntry.PrepRequired = a.Prep;
                        }
                    }

                    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();
            }
        }