示例#1
0
        /// <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();
            }
        }
示例#2
0
        private bool LoadByPrimaryKeyDynamic(System.Int32 shippingServiceId, System.String name)
        {
            ShippingServiceSettingQuery query = new ShippingServiceSettingQuery();

            query.Where(query.ShippingServiceId == shippingServiceId, query.Name == name);
            return(this.Load(query));
        }
示例#3
0
        public Dictionary <string, string> GetSettingsDictionary()
        {
            Dictionary <string, string> settings = new Dictionary <string, string>();

            ShippingServiceSettingQuery q = new ShippingServiceSettingQuery();

            q.Select(q.Name, q.Value);
            q.Where(q.ShippingServiceId == this.Id.GetValueOrDefault(-1));

            using (IDataReader reader = q.ExecuteReader())
            {
                while (reader.Read())
                {
                    settings[reader.GetString(0)] = reader.GetString(1);
                }
                reader.Close();
            }

            return(settings);
        }