public void SaveIncidents(IList <ITollIncident> sentIncidents) { try { using (var ctx = new TollDataContext()) { ctx.context.Configuration.AutoDetectChangesEnabled = false; foreach (var sentIncident in sentIncidents) { var mappedIncident = Mapper.Map <ITollIncident, Incident>(sentIncident); ctx.context.Entry(mappedIncident).State = EntityState.Modified; } ctx.Save(); } } catch (Exception ex) { Log.LogException(ex); Log.LogTrace(ex.Message + ". Check error log for more details."); Log.LogInfoMessage("About to start saving transactions individually."); foreach (var sentIncident in sentIncidents) { using (var ctx = new TollDataContext()) { ctx.context.Configuration.AutoDetectChangesEnabled = false; var mappedIncident = Mapper.Map <ITollIncident, Incident>(sentIncident); ctx.context.Entry(mappedIncident).State = EntityState.Modified; ctx.Save(); } } } }
public void SaveTransactions(IList <ITollTransaction> sentTransactions) { try { using (var ctx = new TollDataContext()) { ctx.context.Configuration.AutoDetectChangesEnabled = false; foreach (var sentTransaction in sentTransactions) { var mappedtransaction = Mapper.Map <ITollTransaction, Transaction>(sentTransaction); ctx.context.Entry(mappedtransaction).State = EntityState.Modified; } ctx.Save(); } } catch (System.Data.Entity.Validation.DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Log.LogErrorMessage(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State)); foreach (var ve in eve.ValidationErrors) { Log.LogErrorMessage(string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage)); } } throw; } catch (Exception ex) { Log.LogException(ex); Log.LogTrace(ex.Message + ". Check error log for more details."); Log.LogInfoMessage("About to start saving transactions individually."); foreach (ITollTransaction sentTransaction in sentTransactions) { using (var ctx = new TollDataContext()) { try { ctx.context.Configuration.AutoDetectChangesEnabled = false; Transaction mappedtransaction = Mapper.Map <ITollTransaction, Transaction>(sentTransaction); ctx.context.Entry(mappedtransaction).State = EntityState.Modified; ctx.Save(); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Log.LogErrorMessage(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State)); foreach (var ve in eve.ValidationErrors) { Log.LogErrorMessage(string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage)); } } } catch (Exception e) { Log.LogException(ex); Log.LogTrace(ex.Message + ". Check error log for more details."); Log.LogInfoMessage("About to start saving transactions individually."); } } } } }