Пример #1
0
 public void OnUpdateError(ActiveRecordDataSourceUpdateEventArgs e)
 {
     if (UpdateError != null)
     {
         UpdateError(this, e);
     }
 }
Пример #2
0
 public void OnBeforeUpdate(ActiveRecordDataSourceUpdateEventArgs e)
 {
     if (BeforeUpdate != null)
     {
         BeforeUpdate(this, e);
     }
 }
Пример #3
0
        protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
        {
            ActiveRecordDataSourceUpdateEventArgs args = new ActiveRecordDataSourceUpdateEventArgs();

            args.ModelType    = BuildManager.GetType(Source.TypeName, false, true);
            args.UpdateValues = values;

            CreateValuesFromUpdateParameters(args);

            IClassMetadata meta = ActiveRecordMediator.GetSessionFactoryHolder().GetSessionFactory(args.ModelType).GetClassMetadata(args.ModelType);

            if (!meta.HasIdentifierProperty)
            {
                throw new ApplicationException("ActiveRecordDataSourceView requires a primary key for the update method.");
            }

            args.KeyProperty = meta.IdentifierPropertyName;
            args.KeyValue    = keys[meta.IdentifierPropertyName];

            try
            {
                args.Entity = ActiveRecordMediator.FindByPrimaryKey(args.ModelType, args.KeyValue);

                Source.OnBeforeUpdate(args);

                if (args.Cancel)
                {
                    return(0);
                }

                foreach (string key in args.UpdateValues.Keys)
                {
                    meta.SetPropertyValue(args.Entity, key, args.UpdateValues[key]);
                }

                ActiveRecordMediator.Update(args.Entity);
            }
            catch (Exception e)
            {
                args.Exception = e;
                args.WasError  = true;

                Source.OnUpdateError(args);

                if (Source.ThrowOnError && !args.DoNotThrow)
                {
                    throw;
                }

                return(0);
            }

            Source.OnUpdate(args);

            return(1);
        }
Пример #4
0
        protected void CreateValuesFromUpdateParameters(ActiveRecordDataSourceUpdateEventArgs args)
        {
            IOrderedDictionary values = UpdateParameters.GetValues(HttpContext.Current, Source);

            for (int i = 0; i < UpdateParameters.Count; i++)
            {
                Parameter parameter = UpdateParameters[i];
                args.UpdateValues[parameter.Name] = values[i];
            }
        }
        protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
        {
            ActiveRecordDataSourceUpdateEventArgs args = new ActiveRecordDataSourceUpdateEventArgs();
            args.ModelType = BuildManager.GetType(Source.TypeName, false, true);
            args.UpdateValues = values;

            CreateValuesFromUpdateParameters(args);

            IClassMetadata meta = ActiveRecordMediator.GetSessionFactoryHolder().GetSessionFactory(args.ModelType).GetClassMetadata(args.ModelType);
            if (!meta.HasIdentifierProperty)
                throw new ApplicationException("ActiveRecordDataSourceView requires a primary key for the update method.");

            args.KeyProperty = meta.IdentifierPropertyName;
            args.KeyValue = keys[meta.IdentifierPropertyName];

            try
            {
                args.Entity = ActiveRecordMediator.FindByPrimaryKey(args.ModelType, args.KeyValue);

                Source.OnBeforeUpdate(args);

                if (args.Cancel)
                    return 0;

                foreach (string key in args.UpdateValues.Keys)
                {
                    meta.SetPropertyValue(args.Entity, key, args.UpdateValues[key]);
                }

                ActiveRecordMediator.Update(args.Entity);
            }
            catch (Exception e)
            {
                args.Exception = e;
                args.WasError = true;

                Source.OnUpdateError(args);

                if (Source.ThrowOnError && !args.DoNotThrow)
                    throw;

                return 0;
            }

            Source.OnUpdate(args);

            return 1;
        }
        protected void CreateValuesFromUpdateParameters(ActiveRecordDataSourceUpdateEventArgs args)
        {
            IOrderedDictionary values = UpdateParameters.GetValues(HttpContext.Current, Source);

            for (int i = 0; i < UpdateParameters.Count; i++)
            {
                Parameter parameter = UpdateParameters[i];
                args.UpdateValues[parameter.Name] = values[i];
            }
        }
 public void OnUpdateError(ActiveRecordDataSourceUpdateEventArgs e)
 {
     if (UpdateError != null)
         UpdateError(this, e);
 }
 public void OnBeforeUpdate(ActiveRecordDataSourceUpdateEventArgs e)
 {
     if (BeforeUpdate != null)
         BeforeUpdate(this, e);
 }