public void SaveSettings() { using (var context = new Settings(ConnectionString)) { if (!context.DatabaseExists()) { // create database if it does not exist context.CreateDatabase(); } var query = context.SettingsTable.Where(setting => setting.Id == 0); string s = null; s = UserPreference.PreferredAssociations.Aggregate(s, (current, preferredAssociation) => current + (preferredAssociation.In + ';')); var formatted = s != null?s.Substring(0, s.Length - 1) : ""; SettingsTable settingUpdate = null; if (query.Any()) { settingUpdate = query.First(); } if (!query.Any()) { var sett = new SettingsTable { Associations = formatted, Filtering = Convert.ToString(UserPreference.IsFiltering), Id = 0, CacheDate = _cacheTime.ToString(new CultureInfo("nl-BE")), AccessKey = UserPreference.AccessKey, FbUserId = UserPreference.FbUserId, Name = UserPreference.Name }; context.SettingsTable.InsertOnSubmit(sett); } else { if (settingUpdate != null) { settingUpdate.Filtering = Convert.ToString(UserPreference.IsFiltering); settingUpdate.Associations = formatted; settingUpdate.CacheDate = _cacheTime.ToString(new CultureInfo("nl-BE")); settingUpdate.AccessKey = UserPreference.AccessKey; settingUpdate.FbUserId = UserPreference.FbUserId; settingUpdate.Name = UserPreference.Name; } } context.SubmitChanges(); } }
public void SaveSettings() { using (var context = new Settings(ConnectionString)) { if (!context.DatabaseExists()) { // create database if it does not exist context.CreateDatabase(); } var query = context.SettingsTable.Where(setting => setting.Id == 0); string s = null; s = UserPreference.PreferredAssociations.Aggregate(s, (current, preferredAssociation) => current + (preferredAssociation.In + ';')); var formatted = s != null ? s.Substring(0, s.Length - 1) : ""; SettingsTable settingUpdate = null; if (query.Any()) { settingUpdate = query.First(); } if (!query.Any()) { var sett = new SettingsTable { Associations = formatted, Filtering = Convert.ToString(UserPreference.IsFiltering), Id = 0, CacheDate = _cacheTime.ToString(new CultureInfo("nl-BE")), AccessKey = UserPreference.AccessKey, FbUserId = UserPreference.FbUserId, Name = UserPreference.Name }; context.SettingsTable.InsertOnSubmit(sett); } else { if (settingUpdate != null) { settingUpdate.Filtering = Convert.ToString(UserPreference.IsFiltering); settingUpdate.Associations = formatted; settingUpdate.CacheDate = _cacheTime.ToString(new CultureInfo("nl-BE")); settingUpdate.AccessKey = UserPreference.AccessKey; settingUpdate.FbUserId = UserPreference.FbUserId; settingUpdate.Name = UserPreference.Name; } } context.SubmitChanges(); } }