public override void OnException(IDeleteRequestHandler handler, Exception exception)
 {
     if (exception is SqlException)
     {
         SqlExceptionHelper.HandleDeleteForeignKeyException(exception, handler.Context?.Localizer);
     }
 }
Пример #2
0
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                (Target.Flags & FieldFlags.Updatable) != FieldFlags.Updatable)
            {
                return;
            }

            var idField    = (handler.Row as IIdRow).IdField;
            var row        = rowFactory();
            var rowIdField = (row as IIdRow).IdField;

            var deleteHandler = deleteHandlerFactory();
            var deleteList    = new List <Int64>();

            new SqlQuery()
            .Dialect(handler.Connection.GetDialect())
            .From(row)
            .Select((Field)rowIdField)
            .Where(foreignKeyField == idField[handler.Row].Value)
            .ForEach(handler.Connection, () =>
            {
                deleteList.Add(rowIdField[row].Value);
            });

            foreach (var id in deleteList)
            {
                DeleteDetail(handler.UnitOfWork, id);
            }
        }
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                (Target.Flags & FieldFlags.Updatable) != FieldFlags.Updatable)
                return;

            var idField = (handler.Row as IIdRow).IdField;
            var row = new NoteRow();
            var fld = NoteRow.Fields;

            var deleteList = new List<Int64>();
            new SqlQuery()
                    .From(row)
                    .Select(fld.NoteId)
                    .Where(
                        fld.EntityType == handler.Row.Table &
                        fld.EntityId == idField[handler.Row].Value)
                    .ForEach(handler.Connection, () =>
                    {
                        deleteList.Add(row.NoteId.Value);
                    });

            foreach (var id in deleteList)
                DeleteNote(handler.UnitOfWork, id);
        }
Пример #4
0
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            foreach (var info in infoList)
            {
                if (!info.Attr.CascadeDelete)
                {
                    continue;
                }

                var thisKey = info.ThisKeyField.AsObject(handler.Row);
                if (ReferenceEquals(null, thisKey))
                {
                    continue;
                }

                var oldID = GetExistingID(handler.Connection, info, thisKey);
                if (oldID == null)
                {
                    continue;
                }

                var deleteHandler = DefaultHandlerFactory.DeleteHandlerFor(info.Attr.RowType);
                var deleteRequest = DefaultHandlerFactory.DeleteRequestFor(info.Attr.RowType);
                deleteRequest.EntityId = oldID;
                deleteHandler.Process(handler.UnitOfWork, deleteRequest);
            }
        }
Пример #5
0
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            foreach (var info in infoList)
            {
                if (!info.Attr.CascadeDelete)
                {
                    continue;
                }

                var thisKey = info.ThisKeyField.AsObject(handler.Row);
                if (ReferenceEquals(null, thisKey))
                {
                    continue;
                }

                var oldID = GetExistingID(handler.Connection, info, thisKey);
                if (oldID == null)
                {
                    continue;
                }

                info.DeleteHandlerFactory().Process(handler.UnitOfWork, new Services.DeleteRequest
                {
                    EntityId = oldID
                });
            }
        }
Пример #6
0
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                (Target.Flags & FieldFlags.Updatable) != FieldFlags.Updatable)
                return;

            if (!attr.ForceCascadeDelete && ServiceQueryHelper.UseSoftDelete(handler.Row))
                return;

            var row = rowFactory();
            var rowIdField = (Field)((row as IIdRow).IdField);

            var deleteHandler = deleteHandlerFactory();
            var deleteList = new List<object>();
            new SqlQuery()
                    .Dialect(handler.Connection.GetDialect())
                    .From(row)
                    .Select((Field)rowIdField)
                    .Where(
                            foreignKeyField == new ValueCriteria(masterKeyField.AsObject(handler.Row)) &
                            queryCriteria)
                    .ForEach(handler.Connection, () =>
                    {
                        deleteList.Add(rowIdField.AsObject(row));
                    });

            foreach (var id in deleteList)
                DeleteDetail(handler.UnitOfWork, id);
        }
Пример #7
0
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                (Target.Flags & FieldFlags.Updatable) != FieldFlags.Updatable)
            {
                return;
            }

            var idField = (handler.Row as IIdRow).IdField;
            var row     = new NoteRow();
            var fld     = NoteRow.Fields;

            var deleteList = new List <Int64>();

            new SqlQuery()
            .From(row)
            .Select(fld.NoteId)
            .Where(
                fld.EntityType == handler.Row.Table &
                fld.EntityId == idField[handler.Row].Value)
            .ForEach(handler.Connection, () =>
            {
                deleteList.Add(row.NoteId.Value);
            });

            foreach (var id in deleteList)
            {
                DeleteNote(handler.UnitOfWork, id);
            }
        }
Пример #8
0
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            foreach (var info in infoList)
            {
                if (!info.Attr.CascadeDelete)
                {
                    continue;
                }

                var thisKey = info.ThisKeyField.AsObject(handler.Row);
                if (thisKey is null)
                {
                    continue;
                }

                var oldID = GetExistingID(handler.Connection, info, thisKey);
                if (oldID == null)
                {
                    continue;
                }

                var deleteHandler = handlerFactory.CreateHandler <IDeleteRequestProcessor>(info.Attr.RowType);
                var deleteRequest = deleteHandler.CreateRequest();
                deleteRequest.EntityId = oldID;
                deleteHandler.Process(handler.UnitOfWork, deleteRequest);
            }
        }
Пример #9
0
        public override void OnAudit(IDeleteRequestHandler handler)
        {
            if (handler.Row == null || captureLogHandler == null)
                return;

            captureLogHandler.LogDelete(handler.UnitOfWork, handler.Row, Authorization.UserId.TryParseID().Value);
        }
Пример #10
0
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                (Target.Flags & FieldFlags.Updatable) != FieldFlags.Updatable)
            {
                return;
            }

            var idField    = (Field)((handler.Row as IIdRow).IdField);
            var masterId   = idField.AsObject(handler.Row);
            var row        = rowFactory();
            var rowIdField = (Field)((row as IIdRow).IdField);

            var deleteHandler = deleteHandlerFactory();
            var deleteList    = new List <object>();

            new SqlQuery()
            .Dialect(handler.Connection.GetDialect())
            .From(row)
            .Select(rowIdField)
            .WhereEqual(thisKeyField, masterId)
            .ForEach(handler.Connection, () =>
            {
                deleteList.Add(rowIdField.AsObject(row));
            });

            foreach (var id in deleteList)
            {
                DeleteDetail(handler.UnitOfWork, id);
            }
        }
Пример #11
0
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            if (ServiceQueryHelper.UseSoftDelete(handler.Row))
            {
                return;
            }

            var idField  = (Field)((handler.Row as IIdRow).IdField);
            var localRow = localRowFactory();

            var deleteList = new List <object>();

            new SqlQuery()
            .Dialect(handler.Connection.GetDialect())
            .From(localRow)
            .Select(localRowIdField)
            .Where(
                foreignKeyField == new ValueCriteria(idField.AsObject(handler.Row)))
            .ForEach(handler.Connection, () =>
            {
                deleteList.Add(localRowIdField.AsObject(localRow));
            });

            foreach (var localId in deleteList)
            {
                DeleteLocalRow(handler.UnitOfWork, localId);
            }
        }
Пример #12
0
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            if (Target is null ||
                (Target.Flags & FieldFlags.Updatable) != FieldFlags.Updatable)
            {
                return;
            }

            var idField = (handler.Row as IIdRow).IdField;
            var row     = new NoteRow();
            var fld     = NoteRow.Fields;

            var deleteList = new List <long>();

            new SqlQuery()
            .From(row)
            .Select(fld.NoteId)
            .Where(
                fld.EntityType == handler.Row.Table &
                fld.EntityId == Convert.ToInt64(idField.AsObject(handler.Row),
                                                CultureInfo.InvariantCulture))
            .ForEach(handler.Connection, () =>
            {
                deleteList.Add(row.NoteId.Value);
            });

            foreach (var id in deleteList)
            {
                DeleteNote(handler.UnitOfWork, id);
            }
        }
Пример #13
0
        public override void OnAudit(IDeleteRequestHandler handler)
        {
            var auditRequest = GetAuditDeleteRequest(handler);

            if (auditRequest != null)
            {
                AuditLogService.AuditDelete(handler.UnitOfWork.Connection, RowRegistry.GetConnectionKey(handler.Row), auditRequest);
            }
        }
Пример #14
0
        public override void OnAudit(IDeleteRequestHandler handler)
        {
            if (handler.Row == null || captureLogHandler == null)
            {
                return;
            }

            captureLogHandler.LogDelete(handler.UnitOfWork, handler.Row, Authorization.UserId.TryParseID().Value);
        }
        public override void OnAudit(IDeleteRequestHandler handler)
        {
            var auditRequest = GetAuditDeleteRequest(handler);

            if (auditRequest != null)
            {
                AuditLogService.AuditDelete(handler.UnitOfWork.Connection, handler.Row.GetFields().ConnectionKey, auditRequest);
            }
        }
Пример #16
0
        public void OnValidateRequest(IDeleteRequestHandler handler)
        {
            var user = (UserDefinition)Authorization.UserDefinition;

            if (fldTenantId[handler.Row] != user.TenantId)
            {
                Authorization.ValidatePermission(PermissionKeys.Tenants);
            }
        }
Пример #17
0
        public void OnValidateRequest(IDeleteRequestHandler handler)
        {
            var user = (UserDefinition)Authorization.UserDefinition;

            if (fldIdComercio[handler.Row] != user.Id_Comercio)
            {
                Authorization.ValidatePermission(
                    PermissionKeys.Comercio);
            }
        }
Пример #18
0
        public override void OnAudit(IDeleteRequestHandler handler)
        {
            if (handler.Row == null || captureLogHandler == null)
                return;

            Row newRow = null;

            // if row is not actually deleted, but set to deleted by a flag, log it as if it is an update operation
            if (handler.Row is IIsActiveDeletedRow)
            {
                newRow = handler.Row.Clone();
                ((IIsActiveDeletedRow)newRow).IsActiveField[newRow] = -1;
            }

            captureLogHandler.Log(handler.UnitOfWork, handler.Row, newRow, Authorization.UserId);
        }
        public override void OnAfterDelete(IDeleteRequestHandler handler)
        {
            if (handler.Row is IIsActiveDeletedRow ||
                handler.Row is IDeleteLogRow)
                return;

            var field = (StringField)Target;
            var oldFilesJSON = field[handler.Row].TrimToNull();
            var oldFileList = ParseAndValidate(oldFilesJSON, "oldFiles");

            var filesToDelete = new FilesToDelete();
            UploadHelper.RegisterFilesToDelete(handler.UnitOfWork, filesToDelete);

            foreach (var file in oldFileList)
                DeleteOldFile(filesToDelete, file.Filename);
        }
Пример #20
0
        public override void OnAfterDelete(IDeleteRequestHandler handler)
        {
            if (handler.Row is IIsActiveDeletedRow ||
                handler.Row is IDeleteLogRow)
            {
                return;
            }

            var filename      = (StringField)(Target);
            var oldFilename   = filename[handler.Row];
            var filesToDelete = new FilesToDelete();

            UploadHelper.RegisterFilesToDelete(handler.UnitOfWork, filesToDelete);

            DeleteOldFile(filesToDelete, oldFilename);
        }
Пример #21
0
        public override void OnAudit(IDeleteRequestHandler handler)
        {
            if (handler.Row == null || captureLogHandler == null)
            {
                return;
            }

            Row newRow = null;

            // if row is not actually deleted, but set to deleted by a flag, log it as if it is an update operation
            if (handler.Row is IIsActiveDeletedRow)
            {
                newRow = handler.Row.Clone();
                ((IIsActiveDeletedRow)newRow).IsActiveField[newRow] = -1;
            }

            captureLogHandler.Log(handler.UnitOfWork, handler.Row, newRow, Authorization.UserId);
        }
        public override void OnAfterDelete(IDeleteRequestHandler handler)
        {
            if (ServiceQueryHelper.UseSoftDelete(handler.Row))
            {
                return;
            }

            var field        = (StringField)Target;
            var oldFilesJSON = field[handler.Row].TrimToNull();
            var oldFileList  = ParseAndValidate(oldFilesJSON, "oldFiles");

            var filesToDelete = new FilesToDelete();

            UploadHelper.RegisterFilesToDelete(handler.UnitOfWork, filesToDelete);

            foreach (var file in oldFileList)
            {
                DeleteOldFile(filesToDelete, file.Filename);
            }
        }
Пример #23
0
        protected AuditDeleteRequest GetAuditDeleteRequest(IDeleteRequestHandler handler)
        {
            var idField = ((IIdRow)handler.Row).IdField;

            var auditRequest = new AuditDeleteRequest(handler.Row.Table, idField[handler.Row].Value);

            var parentIdRow = handler.Row as IParentIdRow;
            if (parentIdRow != null)
            {
                var parentIdField = (Field)parentIdRow.ParentIdField;
                //EntityType parentEntityType;
                if (!parentIdField.ForeignTable.IsNullOrEmpty())
                    //SiteSchema.Instance.TableToType.TryGetValue(parentIdField.ForeignTable, out parentEntityType))
                {
                    auditRequest.ParentTypeId = parentIdField.ForeignTable;
                    auditRequest.ParentId = parentIdRow.ParentIdField[handler.Row];
                }
            }

            return auditRequest;
        }
        protected AuditDeleteRequest GetAuditDeleteRequest(IDeleteRequestHandler handler)
        {
            var idField = ((IIdRow)handler.Row).IdField;

            var auditRequest = new AuditDeleteRequest(handler.Row.Table, idField[handler.Row].Value);

            var parentIdRow = handler.Row as IParentIdRow;

            if (parentIdRow != null)
            {
                var parentIdField = (Field)parentIdRow.ParentIdField;
                //EntityType parentEntityType;
                if (!parentIdField.ForeignTable.IsNullOrEmpty())
                //SiteSchema.Instance.TableToType.TryGetValue(parentIdField.ForeignTable, out parentEntityType))
                {
                    auditRequest.ParentTypeId = parentIdField.ForeignTable;
                    auditRequest.ParentId     = parentIdRow.ParentIdField[handler.Row];
                }
            }

            return(auditRequest);
        }
Пример #25
0
        public override void OnAudit(IDeleteRequestHandler handler)
        {
            if (handler.Row == null)
            {
                return;
            }

            IRow newRow = null;

            // if row is not actually deleted, but set to deleted by a flag, log it as if it is an update operation
            if (handler.Row is IIsActiveDeletedRow)
            {
                newRow = handler.Row.Clone();
                ((IIsActiveDeletedRow)newRow).IsActiveField[newRow] = -1;
            }
            else if (handler.Row is IIsDeletedRow)
            {
                newRow = handler.Row.Clone();
                ((IIsDeletedRow)newRow).IsDeletedField[newRow] = true;
            }

            Log(handler.UnitOfWork, handler.Row, newRow, handler.Context.User?.GetIdentifier());
        }
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            if (Target is null ||
                (Target.Flags & FieldFlags.Updatable) != FieldFlags.Updatable)
            {
                return;
            }

            if (!attr.ForceCascadeDelete && ServiceQueryHelper.UseSoftDelete(handler.Row))
            {
                return;
            }

            var idField    = handler.Row.IdField;
            var masterId   = idField.AsObject(handler.Row);
            var row        = rowFactory();
            var rowIdField = row.IdField;

            var deleteList = new List <object>();

            new SqlQuery()
            .Dialect(handler.Connection.GetDialect())
            .From(row)
            .Select(rowIdField)
            .Where(
                thisKeyField == new ValueCriteria(masterId) &
                queryCriteria)
            .ForEach(handler.Connection, () =>
            {
                deleteList.Add(rowIdField.AsObject(row));
            });

            foreach (var id in deleteList)
            {
                DeleteDetail(handler.UnitOfWork, id);
            }
        }
Пример #27
0
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                (Target.Flags & FieldFlags.Updatable) != FieldFlags.Updatable)
            {
                return;
            }

            if (handler.Row is IIsActiveDeletedRow)
            {
                return;
            }

            var idField    = (Field)((handler.Row as IIdRow).IdField);
            var row        = rowFactory();
            var rowIdField = (Field)((row as IIdRow).IdField);

            var deleteHandler = deleteHandlerFactory();
            var deleteList    = new List <object>();

            new SqlQuery(handler.Connection.GetDialect())
            .From(row)
            .Select((Field)rowIdField)
            .Where(
                foreignKeyField == new ValueCriteria(idField.AsObject(handler.Row)) &
                filterCriteriaT0)
            .ForEach(handler.Connection, () =>
            {
                deleteList.Add(rowIdField.AsObject(row));
            });

            foreach (var id in deleteList)
            {
                DeleteDetail(handler.UnitOfWork, id);
            }
        }
Пример #28
0
 public void OnPrepareQuery(IDeleteRequestHandler handler, SqlQuery query)
 {
 }
Пример #29
0
 public void OnBeforeDelete(IDeleteRequestHandler handler)
 {
 }
Пример #30
0
 public void OnAudit(IDeleteRequestHandler handler)
 {
     InsertNewLog(handler.Row, null, AuditActionType.Delete);
 }
Пример #31
0
 public void OnAfterDelete(IDeleteRequestHandler handler)
 {
 }
Пример #32
0
 public virtual void OnReturn(IDeleteRequestHandler handler)
 {
 }
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                (Target.Flags & FieldFlags.Updatable) != FieldFlags.Updatable)
                return;

            if (handler.Row is IIsActiveDeletedRow)
                return;

            var idField = (Field)((handler.Row as IIdRow).IdField);
            var masterId = idField.AsObject(handler.Row);
            var row = rowFactory();
            var rowIdField = (Field)((row as IIdRow).IdField);

            var deleteHandler = deleteHandlerFactory();
            var deleteList = new List<object>();
            new SqlQuery()
                    .Dialect(handler.Connection.GetDialect())
                    .From(row)
                    .Select(rowIdField)
                    .Where(
                        thisKeyField == new ValueCriteria(masterId) &
                        filterCriteriaT0)
                    .ForEach(handler.Connection, () =>
                    {
                        deleteList.Add(rowIdField.AsObject(row));
                    });

            foreach (var id in deleteList)
                DeleteDetail(handler.UnitOfWork, id);
        }
Пример #34
0
 public virtual void OnAudit(IDeleteRequestHandler handler)
 {
 }
 public static DeleteRequest CreateRequest(this IDeleteRequestHandler handler)
 {
     return((DeleteRequest)Activator.CreateInstance(handler.GetRequestType()));
 }
Пример #36
0
 public virtual void OnBeforeDelete(IDeleteRequestHandler handler)
 {
 }
 public void OnValidateRequest(IDeleteRequestHandler handler)
 {
     var user = (UserDefinition)Authorization.UserDefinition;
     if (fldTenantId[handler.Row] != user.TenantId)
         Authorization.ValidatePermission(PermissionKeys.Tenants);
 }
Пример #38
0
 public virtual void OnAfterDelete(IDeleteRequestHandler handler)
 {
 }
Пример #39
0
 public virtual void OnValidateRequest(IDeleteRequestHandler handler)
 {
 }
Пример #40
0
 public void OnReturn(IDeleteRequestHandler handler)
 {
 }
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                (Target.Flags & FieldFlags.Updatable) != FieldFlags.Updatable)
                return;

            var idField = (handler.Row as IIdRow).IdField;
            var row = rowFactory();
            var rowIdField = (row as IIdRow).IdField;

            var deleteHandler = deleteHandlerFactory();
            var deleteList = new List<Int64>();
            new SqlQuery()
                    .From(row)
                    .Select((Field)rowIdField)
                    .Where(foreignKeyField == idField[handler.Row].Value)
                    .ForEach(handler.Connection, () =>
                    {
                        deleteList.Add(rowIdField[row].Value);
                    });

            foreach (var id in deleteList)
                DeleteDetail(handler.UnitOfWork, id);
        }
Пример #42
0
 public void OnValidateRequest(IDeleteRequestHandler handler)
 {
 }
Пример #43
0
 public override void OnAudit(IDeleteRequestHandler handler)
 {
     var auditRequest = GetAuditDeleteRequest(handler);
     if (auditRequest != null)
         AuditLogService.AuditDelete(handler.UnitOfWork.Connection, RowRegistry.GetConnectionKey(handler.Row), auditRequest);
 }
        public override void OnBeforeDelete(IDeleteRequestHandler handler)
        {
            foreach (var info in infoList)
            {
                if (!info.Attr.CascadeDelete)
                    continue;

                var thisKey = info.ThisKeyField.AsObject(handler.Row);
                if (ReferenceEquals(null, thisKey))
                    continue;

                var oldID = GetExistingID(handler.Connection, info, thisKey);
                if (oldID == null)
                    continue;

                info.DeleteHandlerFactory().Process(handler.UnitOfWork, new Services.DeleteRequest
                {
                    EntityId = oldID
                });
            }
        }
Пример #45
0
        public override void OnAfterDelete(IDeleteRequestHandler handler)
        {
            if (handler.Row is IIsActiveDeletedRow ||
                handler.Row is IDeleteLogRow)
                return;

            var filename = (StringField)(Target);
            var oldFilename = filename[handler.Row];
            var filesToDelete = new FilesToDelete();
            UploadHelper.RegisterFilesToDelete(handler.UnitOfWork, filesToDelete);

            DeleteOldFile(filesToDelete, oldFilename);
        }
Пример #46
0
 public void OnAudit(IDeleteRequestHandler handler)
 {
 }
Пример #47
0
 public virtual void OnPrepareQuery(IDeleteRequestHandler handler, SqlQuery query)
 {
 }