/// <summary> /// This will DELETE and then INSERT each setting /// </summary> /// <param name="shippingServiceId"></param> /// <param name="settings"></param> public void UpdateSettingsDictionary(Dictionary <string, string> settings) { using (esTransactionScope transaction = new esTransactionScope()) { // DELETE all existing settings for this service ShippingServiceSettingQuery qDelete = new ShippingServiceSettingQuery(); qDelete.Where(qDelete.ShippingServiceId == this.Id.Value); ShippingServiceSettingCollection oldSettings = new ShippingServiceSettingCollection(); oldSettings.Load(qDelete); oldSettings.MarkAllAsDeleted(); oldSettings.Save(); // INSERT new settings for this service if (settings.Keys.Count > 0) { ShippingServiceSettingCollection newSettings = new ShippingServiceSettingCollection(); foreach (KeyValuePair <string, string> setting in settings) { ShippingServiceSetting newSetting = newSettings.AddNew(); newSetting.ShippingServiceId = this.Id.Value; newSetting.Name = setting.Key; newSetting.Value = setting.Value; } newSettings.Save(); } transaction.Complete(); } }
static public void Delete(System.Int32 shippingServiceId, System.String name, esSqlAccessType sqlAccessType) { var obj = new ShippingServiceSetting(); obj.ShippingServiceId = shippingServiceId; obj.Name = name; obj.AcceptChanges(); obj.MarkAsDeleted(); obj.Save(sqlAccessType); }