Beispiel #1
0
        protected virtual void DoGenericAudit()
        {
            var auditFields = new HashSet <Field>();

            GetEditableFields(auditFields);

            var auditRequest = GetAuditRequest(auditFields);

            if (IsUpdate)
            {
                Row audit = null;
                if (auditRequest != null)
                {
                    audit = AuditLogService.PrepareAuditUpdate(RowRegistry.GetSchemaName(Row), auditRequest);
                }

                if (audit != null)
                {
                    new SqlInsert(audit).Execute(Connection);
                }
            }
            else if (IsCreate)
            {
                if (auditRequest != null)
                {
                    AuditLogService.AuditInsert(Connection, RowRegistry.GetSchemaName(Row), auditRequest);
                }
            }
        }
        protected virtual void DoGenericAudit()
        {
            var auditRequest = GetAuditRequest();

            if (auditRequest != null)
            {
                AuditLogService.AuditUndelete(Connection, RowRegistry.GetSchemaName(Row), auditRequest);
            }
        }
Beispiel #3
0
        public DbLookupScript(string name, string schema = null, bool authorize = false, string right = null, bool nonCached = false,
                              Func <IDbConnection, IEnumerable <TItem> > getItems = null)
        {
            _lookupParams = new Dictionary <string, object>();

            Row row = null;

            if (typeof(TItem).IsSubclassOf(typeof(Row)))
            {
                row = (Row)(object)(new TItem());
            }

            if (name == null)
            {
                if (row == null)
                {
                    throw new ArgumentNullException("name");
                }

                name = row.Table;
            }

            if (row != null)
            {
                Field field;

                var idRow = row as IIdRow;
                if (idRow != null)
                {
                    field   = ((Field)idRow.IdField);
                    IdField = field.PropertyName ?? field.Name;
                }

                var nameRow = row as INameRow;
                if (nameRow != null)
                {
                    field     = ((Field)nameRow.NameField);
                    TextField = field.PropertyName ?? field.Name;
                }

                var treeRow = row as IParentIdRow;
                if (treeRow != null)
                {
                    field         = ((Field)treeRow.ParentIdField);
                    ParentIdField = field.PropertyName ?? field.Name;
                }
            }

            _scriptName = "Lookup." + name;

            if (schema == null)
            {
                if (row != null)
                {
                    schema = RowRegistry.GetSchemaName(row);
                }
                else
                {
                    schema = RowRegistry.DefaultSchema;
                }
            }

            _schema = schema;

            _lookup    = name;
            _getItems  = getItems;
            _authorize = authorize;
            _right     = right;
            _nonCached = nonCached;

            if (row != null)
            {
                GlobalGenerationKey = row.GetFields().GenerationKey;
            }

            LocalExpiration  = CacheExpiration.Never;
            RemoteExpiration = CacheExpiration.OneDay;

            DynamicScriptManager.Register(this);
        }
Beispiel #4
0
        public override void OnValidateRequest(ISaveRequestHandler handler)
        {
            base.OnValidateRequest(handler);

            var row      = handler.Row;
            var old      = handler.Old;
            var isUpdate = old == null;

            var parentIdRow = row as IParentIdRow;

            if (parentIdRow == null)
            {
                return;
            }

            var parentId = parentIdRow.ParentIdField[row];

            if (parentId == null)
            {
                return;
            }

            if (isUpdate && parentId == parentIdRow.ParentIdField[old])
            {
                return;
            }

            var parentIdField = (Field)parentIdRow.ParentIdField;

            if (parentIdField.ForeignTable.IsNullOrEmpty())
            {
                return;
            }

            var foreignRow = RowRegistry.GetSchemaRow(RowRegistry.GetSchemaName(row),
                                                      parentIdField.ForeignTable);

            if (foreignRow == null)
            {
                return;
            }

            var idForeign = (IIdRow)foreignRow;

            if (idForeign == null)
            {
                return;
            }

            var isActiveForeign = (IIsActiveRow)foreignRow;

            if (isActiveForeign == null)
            {
                return;
            }

            ServiceHelper.CheckParentNotDeleted(handler.UnitOfWork.Connection, foreignRow.Table,
                                                query => query.Where(
                                                    new Criteria((Field)idForeign.IdField) == parentId.Value &
                                                    new Criteria(isActiveForeign.IsActiveField) < 0));
        }