/// <summary>Save client organization CDI data</summary> void SaveOrganizations() { try { string connectionString = ConfigurationManager.AppSettings.Get("ConnectionString"); using (SqlConnection connection = new SqlConnection(connectionString)) using (DataContext db = new DataContext(connection)) { //db.Log = CDIEventLog.Instance; Table <OrganizationSentiment> table = db.GetTable <OrganizationSentiment>(); OrganizationSentiment.Initialize(db); foreach (Customer customer in _customers) { customer.Save(db, table); } db.SubmitChanges(); // only keep the records for organizations with data OrganizationSentiment.DeleteRemainder(db); db.SubmitChanges(); } } catch (Exception e) { CDIEventLog.Instance.WriteEntry("Save failed", e); } }
DBChangeType GetQueryType(double?score, out OrganizationSentiment organizationSentiment) { if (OrganizationSentiment.TryPop(_organizationAnalysis.OrganizationID, out organizationSentiment)) { if (!score.HasValue) { return(DBChangeType.DELETE); } else if (Math.Floor(score.Value) != Math.Floor(organizationSentiment.OrganizationSentimentScore)) { return(DBChangeType.UPDATE); } } else if (score.HasValue) { return(DBChangeType.INSERT); } return(DBChangeType.NONE); }