Exemplo n.º 1
0
 public void OnCreateError(ActiveRecordDataSourceCreateEventArgs e)
 {
     if (CreateError != null)
     {
         CreateError(this, e);
     }
 }
Exemplo n.º 2
0
 public void OnBeforeCreate(ActiveRecordDataSourceCreateEventArgs e)
 {
     if (BeforeCreate != null)
     {
         BeforeCreate(this, e);
     }
 }
Exemplo n.º 3
0
        protected override int ExecuteInsert(IDictionary values)
        {
            ActiveRecordDataSourceCreateEventArgs args = new ActiveRecordDataSourceCreateEventArgs();

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

            CreateValuesFromCreateParameters(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.");
            }

            Source.OnBeforeCreate(args);

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

            try
            {
                if (args.Entity == null)
                {
                    args.Entity = Activator.CreateInstance(args.ModelType);
                }

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

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

                Source.OnCreateError(args);

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

                return(0);
            }

            Source.OnCreate(args);

            return(1);
        }
Exemplo n.º 4
0
        protected void CreateValuesFromCreateParameters(ActiveRecordDataSourceCreateEventArgs args)
        {
            IOrderedDictionary values = CreateParameters.GetValues(HttpContext.Current, Source);

            for (int i = 0; i < CreateParameters.Count; i++)
            {
                Parameter parameter = CreateParameters[i];
                args.CreateValues[parameter.Name] = values[i];
            }
        }
        protected override int ExecuteInsert(IDictionary values)
        {
            ActiveRecordDataSourceCreateEventArgs args = new ActiveRecordDataSourceCreateEventArgs();
            args.ModelType = BuildManager.GetType(Source.TypeName, false, true);
            args.CreateValues = values;

            CreateValuesFromCreateParameters(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.");

            Source.OnBeforeCreate(args);

            if (args.Cancel)
                return 0;

            try
            {
                if (args.Entity == null)
                    args.Entity = Activator.CreateInstance(args.ModelType);

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

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

                Source.OnCreateError(args);

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

                return 0;
            }

            Source.OnCreate(args);

            return 1;
        }
        protected void CreateValuesFromCreateParameters(ActiveRecordDataSourceCreateEventArgs args)
        {
            IOrderedDictionary values = CreateParameters.GetValues(HttpContext.Current, Source);

            for (int i = 0; i < CreateParameters.Count; i++)
            {
                Parameter parameter = CreateParameters[i];
                args.CreateValues[parameter.Name] = values[i];
            }
        }
 public void OnCreateError(ActiveRecordDataSourceCreateEventArgs e)
 {
     if (CreateError != null)
         CreateError(this, e);
 }
 public void OnBeforeCreate(ActiveRecordDataSourceCreateEventArgs e)
 {
     if (BeforeCreate != null)
         BeforeCreate(this, e);
 }