Beispiel #1
0
        public override void Insert(IDictionary values, DataSourceViewOperationCallback callback)
        {
            try
            {
                ISoodaObjectFactory fact = SoodaTransaction.ActiveTransaction.GetFactory(_owner.ClassName);
                SoodaObject         obj  = fact.CreateNew(SoodaTransaction.ActiveTransaction);
                Type type = obj.GetType();

                foreach (DictionaryEntry v in values)
                {
                    PropertyInfo pi = type.GetProperty((string)v.Key, BindingFlags.Public | BindingFlags.Instance);
                    if (pi == null)
                    {
                        throw new SoodaException(v.Key + " not found in " + type.FullName);
                    }

                    pi.SetValue(obj, v.Value, null);
                }
                callback(1, null);
            }
            catch (Exception ex)
            {
                callback(0, ex);
            }
        }
Beispiel #2
0
        public override void Update(System.Collections.IDictionary keys, System.Collections.IDictionary values, System.Collections.IDictionary oldValues, System.Web.UI.DataSourceViewOperationCallback callback)
        {
            try
            {
                if (keys.Count == 0)
                {
                    throw new SoodaException("No keys passed to SoodaObjectDataSourceView.Update");
                }

                if (keys.Count > 1)
                {
                    throw new SoodaException("More than one key passed to SoodaObjectDataSourceView.Update");
                }

                ISoodaObjectFactory fact = SoodaTransaction.ActiveTransaction.GetFactory(_owner.ClassName);

                // we just want to get the first key from "keys"
                // therefore we break at the end of the loop

                foreach (DictionaryEntry de in keys)
                {
                    SoodaObject obj = SoodaTransaction.ActiveTransaction.GetObject(_owner.ClassName,
                                                                                   Convert.ToString(de.Value));

                    Type type = obj.GetType();

                    foreach (DictionaryEntry v in values)
                    {
                        if (oldValues[v.Key] != v.Value)
                        {
                            PropertyInfo pi = type.GetProperty((string)v.Key, BindingFlags.Public | BindingFlags.Instance);
                            if (pi == null)
                            {
                                throw new SoodaException(v.Key + " not found in " + type.FullName);
                            }

                            pi.SetValue(obj, v.Value, null);
                        }
                    }
                    break;
                }
                callback(1, null);
            }
            catch (Exception ex)
            {
                callback(0, ex);
            }
        }