Esempio n. 1
0
        /// <summary>
        /// Retorna objeto somente pela PK
        /// </summary>
        /// <param name="pDto">Objeto</param>
        public TDto Get(TDto pDto)
        {
            DBExecution _execution = DBExecution.NewConstructor();
            DBParameter _parameter = DBParameter.NewConstructor();

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

                var _dataSet = _execution.ExecuteDataSet(_parameter.Parameter, CommandType.StoredProcedure, this.CommandGet);

                if (_dataSet != null && _dataSet.Tables[0].Rows.Count > 0)
                {
                    return(this.Convert(_dataSet.Tables[0].Rows[0]));
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                if (ex is Exception)
                {
                    throw;
                }
                else
                {
                    throw new Exception(this.ErrorMessageGet);
                }
            }
            finally { _execution.Dispose(); }
        }
Esempio n. 2
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(); }
        }
Esempio n. 3
0
        /// <summary>
        /// Retorna objeto aplicando os filtros informados
        /// </summary>
        /// <param name="pDto">Objeto</param>
        public List <TDto> GetByParameters(TDto pDto)
        {
            DBExecution _execution = DBExecution.NewConstructor();
            DBParameter _parameter = DBParameter.NewConstructor();

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

                var _objDataSet = _execution.ExecuteDataSet(_parameter.Parameter, CommandType.StoredProcedure, this.CommandGetByParameters);

                if (_objDataSet != null && _objDataSet.Tables[0].Rows.Count > 0)
                {
                    var _resultSet = new List <TDto>();

                    foreach (DataRow _objDataRow in _objDataSet.Tables[0].Rows)
                    {
                        _resultSet.Add(this.Convert(_objDataRow));
                    }

                    return(_resultSet);
                }
                else
                {
                    return(new List <TDto>());
                }
            }
            catch (Exception ex)
            {
                if (ex is Exception)
                {
                    throw;
                }
                else
                {
                    throw new Exception(this.ErrorMessageGetByParameters);
                }
            }
            finally { _execution.Dispose(); }
        }
Esempio n. 4
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(); }
        }