Пример #1
0
        public TDeleteResponse Process(IUnitOfWork unitOfWork, TDeleteRequest request)
        {
            StateBag.Clear();

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

            ValidatePermissions();

            UnitOfWork = unitOfWork;

            Request  = request;
            Response = new TDeleteResponse();

            if (request.EntityId == null)
            {
                throw DataValidation.RequiredError("EntityId");
            }

            Row = new TRow();

            var idField = (Field)Row.IdField;

            LoadEntity();

            ValidateRequest();

            var isActiveDeletedRow = Row as IIsActiveDeletedRow;
            var isDeletedRow       = Row as IIsDeletedRow;
            var deleteLogRow       = Row as IDeleteLogRow;

            if ((isDeletedRow != null && isDeletedRow.IsDeletedField[Row] == true) ||
                (isActiveDeletedRow != null && isActiveDeletedRow.IsActiveField[Row] < 0) ||
                (deleteLogRow != null && !((Field)deleteLogRow.DeleteUserIdField).IsNull(Row)))
            {
                Response.WasAlreadyDeleted = true;
            }
            else
            {
                OnBeforeDelete();

                ExecuteDelete();

                OnAfterDelete();

                DoAudit();
            }

            OnReturn();

            return(Response);
        }
Пример #2
0
        public TDeleteResponse Process(IUnitOfWork unitOfWork, TDeleteRequest request)
        {
            if (unitOfWork == null)
            {
                throw new ArgumentNullException("unitOfWork");
            }

            ValidatePermissions();

            UnitOfWork = unitOfWork;

            Request  = request;
            Response = new TDeleteResponse();

            if (request.EntityId == null)
            {
                throw DataValidation.RequiredError("EntityId");
            }

            Row = new TRow();

            var idField = (Field)Row.IdField;

            LoadEntity();

            ValidateRequest();

            var isActiveRow = Row as IIsActiveRow;

            if (isActiveRow != null &&
                !ShouldActuallyDelete &&
                isActiveRow.IsActiveField[Row] < 0)
            {
                Response.WasAlreadyDeleted = true;
            }
            else
            {
                OnBeforeDelete();

                ExecuteDelete();

                OnAfterDelete();

                DoAudit();
            }

            OnReturn();

            return(Response);
        }
Пример #3
0
        public TRetrieveResponse Process(IDbConnection connection, TRetrieveRequest request)
        {
            StateBag.Clear();

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

            request.CheckNotNull();
            if (request.EntityId == null)
            {
                throw DataValidation.RequiredError("entityId");
            }

            Connection = connection;
            Request    = request;
            ValidateRequest();

            Response = new TRetrieveResponse();
            Row      = new TRow();

            this.Query = CreateQuery();

            PrepareQuery(Query);

            OnBeforeExecuteQuery();

            if (Query.GetFirst(Connection))
            {
                Response.Entity = Row;
            }
            else
            {
                throw DataValidation.EntityNotFoundError(Row, request.EntityId);
            }

            OnAfterExecuteQuery();

            OnReturn();
            return(Response);
        }
Пример #4
0
        public TRetrieveResponse Process(IDbConnection connection, TRetrieveRequest request)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            request.CheckNotNull();
            if (request.EntityId == null)
            {
                throw DataValidation.RequiredError("entityId");
            }

            Connection = connection;
            Request    = request;
            ValidatePermissions();

            Response = new TRetrieveResponse();
            Row      = new TRow();

            var query = CreateQuery();

            PrepareQuery(query);

            if (query.GetFirst(Connection))
            {
                Response.Entity = Row;
            }
            else
            {
                throw DataValidation.EntityNotFoundError(Row, request.EntityId.Value);
            }

            OnReturn();
            return(Response);
        }
Пример #5
0
        public TUndeleteResponse Process(IUnitOfWork unitOfWork, UndeleteRequest request)
        {
            UnitOfWork = unitOfWork ?? throw new ArgumentNullException("unitOfWork");

            ValidatePermissions();

            Request  = request;
            Response = new TUndeleteResponse();

            if (request.EntityId == null)
            {
                throw DataValidation.RequiredError("EntityId", Localizer);
            }

            Row = new TRow();

            var isActiveDeletedRow = Row as IIsActiveDeletedRow;
            var isDeletedRow       = Row as IIsDeletedRow;
            var deleteLogRow       = Row as IDeleteLogRow;

            if (isActiveDeletedRow == null && isDeletedRow == null && deleteLogRow == null)
            {
                throw new NotImplementedException();
            }

            var idField = Row.IdField;
            var id      = idField.ConvertValue(Request.EntityId, CultureInfo.InvariantCulture);

            LoadEntity();

            ValidateRequest();

            if ((isDeletedRow != null && isDeletedRow.IsDeletedField[Row] != true) ||
                (isActiveDeletedRow != null && isActiveDeletedRow.IsActiveField[Row] >= 0) ||
                (deleteLogRow != null && deleteLogRow.DeleteUserIdField.IsNull(Row)))
            {
                Response.WasNotDeleted = true;
            }
            else
            {
                OnBeforeUndelete();

                var update = new SqlUpdate(Row.Table)
                             .WhereEqual(idField, id);

                if (isActiveDeletedRow != null)
                {
                    update.Set(isActiveDeletedRow.IsActiveField, 1)
                    .WhereEqual(isActiveDeletedRow.IsActiveField, -1);
                }
                else if (isDeletedRow != null)
                {
                    update.Set(isDeletedRow.IsDeletedField, false)
                    .WhereEqual(isDeletedRow.IsDeletedField, 1);
                }

                if (deleteLogRow != null)
                {
                    update.Set(deleteLogRow.DeleteUserIdField, null)
                    .Set(deleteLogRow.DeleteDateField, null);

                    if (isActiveDeletedRow == null && isDeletedRow == null)
                    {
                        update.Where(deleteLogRow.DeleteUserIdField.IsNotNull());
                    }
                }

                if (update.Execute(Connection) != 1)
                {
                    throw DataValidation.EntityNotFoundError(Row, id, Localizer);
                }

                InvalidateCacheOnCommit();

                OnAfterUndelete();

                DoAudit();
            }

            OnReturn();

            return(Response);
        }
Пример #6
0
        public TUndeleteResponse Process(IUnitOfWork unitOfWork, UndeleteRequest request)
        {
            if (unitOfWork == null)
            {
                throw new ArgumentNullException("unitOfWork");
            }

            ValidatePermissions();

            UnitOfWork = unitOfWork;

            Request  = request;
            Response = new TUndeleteResponse();

            if (request.EntityId == null)
            {
                throw DataValidation.RequiredError("EntityId");
            }

            Row = new TRow();

            var isActiveRow = Row as IIsActiveRow;

            if (isActiveRow == null)
            {
                throw new NotImplementedException();
            }

            var idField = (Field)Row.IdField;

            LoadEntity();

            ValidateRequest();

            if (isActiveRow.IsActiveField[Row] > 0)
            {
                Response.WasNotDeleted = true;
            }
            else
            {
                OnBeforeUndelete();

                if (new SqlUpdate(Row.Table)
                    .Set(isActiveRow.IsActiveField, 1)
                    .WhereEqual(idField, request.EntityId.Value)
                    .WhereEqual(isActiveRow.IsActiveField, -1)
                    .Execute(Connection) != 1)
                {
                    throw DataValidation.EntityNotFoundError(Row, request.EntityId.Value);
                }

                InvalidateCacheOnCommit();

                OnAfterUndelete();

                DoAudit();
            }

            OnReturn();

            return(Response);
        }