Exemplo n.º 1
0
        /// <summary>
        /// Save Entity using rowstate
        /// </summary>
        /// <param name="item">item to modify</param>
        /// <param name="command">Command to (re)use</param>
        /// <returns> greater than zeor, if succes</returns>
        public int Save(T item, IDbCommand command)
        {
            int result = -1;
            Func <T, IDbCommand, int> execute   = null;
            DefaulDatabaseOperation   operation = DefaulDatabaseOperation.None;

            if (item.RowState == DataRowState.Added)
            {
                operation = DefaulDatabaseOperation.Create;
                execute   = this.Create;
            }
            else if (item.RowState == DataRowState.Deleted)
            {
                operation = DefaulDatabaseOperation.Delete;
                execute   = this.Delete;
            }
            else if (item.RowState == DataRowState.Modified)
            {
                operation = DefaulDatabaseOperation.Update;
                execute   = this.Update;
            }

            if (execute != null)
            {
                command.CommandText = this.Operations[operation];
                this.FillParameter(item, command, operation);
                result = execute(item, command);
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Execute single command
        /// </summary>
        /// <param name="execute">Method to execute</param>
        /// <param name="item">IDataTransferObject</param>
        /// <param name="operation">Database Operation like CRUD</param>
        /// <returns></returns>
        protected int Execute(Func <T, IDbCommand, int> execute, T item, DefaulDatabaseOperation operation)
        {
            int result     = -1;
            var connection = this.OpenConnection();

            using (IDbCommand command = connection.CreateCommand())
            {
                this.OutputParameters.Clear();
                command.CommandType = this.DefaultCommandType;
                command.CommandText = this.Operations[operation];
                this.FillParameter(item, command, operation);
                command.Prepare();
                result = execute(item, command);
                this.OutputParameters.AddRange(command.Parameters.OfType <IDbDataParameter>().Where(a => a.Direction != ParameterDirection.Input));
            }

            return(result);
        }
Exemplo n.º 3
0
 public abstract void FillParameter(T item, IDbCommand command, DefaulDatabaseOperation operation);
Exemplo n.º 4
0
 /// <summary>
 /// Use to fill Data for SSE
 /// </summary>
 /// <param name="item">placeholder for data</param>
 /// <param name="command">Existing Command to use. Allow directly create new Parameter</param>
 /// <param name="operation">include operation for current execution</param>
 void IDataAccessLayer.FillParameter(IDataTransferObject item, IDbCommand command, DefaulDatabaseOperation operation)
 {
     this.FillParameter(item as T, command, operation);
 }