Exemplo n.º 1
0
        public virtual bool Update(ZOperationResult operationResult, TEntity entity)
        {
            try
            {
                if (entity.BeforeUpdate(operationResult))
                {
                    if (BeforeUpdate(operationResult, entity))
                    {
                        //if (UnitOfWork.BeforeUpdate(operationResult, entity))
                        {
                            Connection.Update <TEntity>(entity);

                            if (entity.AfterUpdate(operationResult))
                            {
                                AfterUpdate(operationResult, entity);
                                //{
                                //    UnitOfWork.AfterUpdate(operationResult, entity);
                                //}
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                operationResult.ParseExceptionLINQ2DB(exception);
            }

            return(operationResult.Ok);
        }
Exemplo n.º 2
0
        public virtual bool CommitTransaction(ZOperationResult operationResult)
        {
            try
            {
                if (PersistenceHelper.IsTransaction)
                {
                    if (Transaction != null)
                    {
                        if (Transaction.DataConnection != null &&
                            Transaction.DataConnection.Connection != null &&
                            Transaction.DataConnection.Connection.State == ConnectionState.Open)
                        {
                            Transaction.Commit();
                        }

                        Transaction.Dispose();
                        Transaction = null;
                    }
                }
            }
            catch (Exception exception)
            {
                operationResult.ParseExceptionLINQ2DB(exception);
            }

            return(operationResult.Ok);
        }
Exemplo n.º 3
0
        public virtual bool Create(ZOperationResult operationResult, TEntity entity)
        {
            try
            {
                if (entity.BeforeCreate(operationResult))
                {
                    if (BeforeCreate(operationResult, entity))
                    {
                        //if (UnitOfWork.BeforeCreate(operationResult, entity))
                        {
                            object id = GetNextSequence();
                            if (id != null)
                            {
                                (entity as ZDataBase).SetId(new object[] { id });
                            }

                            if (Profile.IsIdentity)
                            {
                                object identity = Connection.InsertWithIdentity <TEntity>(entity);
                                (entity as ZDataBase).SetId(new object[] { identity });
                            }
                            else
                            {
                                Connection.Insert <TEntity>(entity);
                            }

                            if (entity.AfterCreate(operationResult))
                            {
                                AfterCreate(operationResult, entity);
                                //{
                                //    UnitOfWork.AfterCreate(operationResult, entity);
                                //}
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                operationResult.ParseExceptionLINQ2DB(exception);
            }

            return(operationResult.Ok);
        }
Exemplo n.º 4
0
        public virtual bool BeginTransaction(ZOperationResult operationResult, bool isTransaction = true, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
        {
            try
            {
                if (isTransaction && PersistenceHelper.IsTransaction)
                {
                    if (Transaction == null || Transaction.DataConnection == null)
                    {
                        Transaction = Connection.BeginTransaction(isolationLevel);
                    }
                }
            }
            catch (Exception exception)
            {
                operationResult.ParseExceptionLINQ2DB(exception);
            }

            return(operationResult.Ok);
        }
Exemplo n.º 5
0
        public virtual bool RollbackTransaction(ZOperationResult operationResult, bool isTransaction = true)
        {
            try
            {
                if (isTransaction && PersistenceHelper.IsTransaction)
                {
                    if (Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
            }
            catch (Exception exception)
            {
                operationResult.ParseExceptionLINQ2DB(exception);
            }

            return(operationResult.Ok);
        }
        public virtual bool Delete(ZOperationResult operationResult, TEntity entity)
        {
            try
            {
                if (UnitOfWork.BeforeDelete(operationResult, entity))
                {
                    if (BeforeDelete(operationResult, entity))
                    {
                        Connection.Delete <TEntity>(entity);

                        if (AfterDelete(operationResult, entity))
                        {
                            UnitOfWork.AfterDelete(operationResult, entity);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                operationResult.ParseExceptionLINQ2DB(exception);
            }

            return(operationResult.Ok);
        }