예제 #1
0
        //TODO: FUTURO...

        #endregion

        #region [ Métodos para Persistência do objeto no banco de dados ]

        /// <summary>
        /// Insere o objeto no banco de dados
        /// </summary>
        /// <param name="pDto"></param>
        /// <param name="pReturnIdentity"></param>
        /// <returns></returns>
        public object Insert(TDto pDto, bool pReturnIdentity = false)
        {
            DBExecution _execution = DBExecution.NewConstructor();
            DBParameter _parameter = DBParameter.NewConstructor();

            try
            {
                this.FillParameters(ref pDto, ref _parameter, ExecutionTypes.Insert);

                if (pReturnIdentity)
                {
                    return(_execution.ExecuteScalar(_parameter.Parameter, System.Data.CommandType.StoredProcedure, this.CommandInsert));
                }
                else
                {
                    return(_execution.ExecuteNonQuery(_parameter.Parameter, System.Data.CommandType.StoredProcedure, this.CommandInsert));
                }
            }
            catch (Exception ex)
            {
                if (ex is Exception)
                {
                    throw;
                }
                else
                {
                    throw new Exception(this.ErrorMessageInsert);
                }
            }
            finally { _execution.Dispose(); }
        }
예제 #2
0
        /// <summary>
        /// "Exclui" o objeto do banco de dados
        /// </summary>
        /// <param name="pDto"></param>
        /// <returns></returns>
        public bool Delete(TDto pDto)
        {
            DBExecution _execution = DBExecution.NewConstructor();
            DBParameter _parameter = DBParameter.NewConstructor();

            try
            {
                this.FillParameters(ref pDto, ref _parameter, ExecutionTypes.Delete);

                return(_execution.ExecuteNonQuery(_parameter.Parameter, CommandType.StoredProcedure, this.CommandDelete) > 0);
            }
            catch (Exception ex)
            {
                if (ex is Exception)
                {
                    throw;
                }
                else
                {
                    throw new Exception(this.ErrorMessageDelete);
                }
            }
            finally { _execution.Dispose(); }
        }