示例#1
0
        public string InsertValorEvento(TipoPublicoValorDao tipoPublicoValorDao)
        {
            bool   _resultado = false;
            string _msg       = "";
            Int32  id         = 0;

            using (SqlConnection connection = new SqlConnection(strConnSql))
            {
                connection.Open();

                SqlCommand     command = connection.CreateCommand();
                SqlTransaction transaction;

                // Start a local transaction.
                transaction = connection.BeginTransaction("IncluirValorEvento");

                command.Connection  = connection;
                command.Transaction = transaction;

                try
                {
                    // Inserindo os dados na tabela:
                    command.CommandText = "" +
                                          "INSERT into dbo.AD_Valor_Evento_Publico (EventoId, Valor, TipoPublicoId, Ativo) " +
                                          "VALUES(@EventoId, @Valor, @TipoPublicoId, @Ativo) " +
                                          "SELECT CAST(scope_identity() AS int) ";

                    command.Parameters.AddWithValue("EventoId", tipoPublicoValorDao.EventoId);
                    command.Parameters.AddWithValue("Valor", tipoPublicoValorDao.ValorAtivo);
                    command.Parameters.AddWithValue("TipoPublicoId", tipoPublicoValorDao.TipoPublicoId);
                    command.Parameters.AddWithValue("Ativo", tipoPublicoValorDao.ValorAtivo);

                    id         = (Int32)command.ExecuteScalar();
                    _resultado = id > 0;

                    _msg = _resultado ? "Inclusão Realizada com sucesso" : "Inclusão Não Realizada com sucesso";

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    // Attempt to roll back the transaction.
                    try
                    {
                        transaction.Rollback();
                    }
                    catch (Exception ex2)
                    {
                        throw new Exception($"Rollback Exception Type:{ex2.GetType()}. Erro:{ex2.Message}");
                    }
                    throw new Exception($"Commit Exception Type:{ex.GetType()}. Erro:{ex.Message}");
                }
                finally
                {
                    connection.Close();
                }
            }
            return(_msg);
        }
示例#2
0
        public string UpdateValorEvento(int id, TipoPublicoValorDao tipoPublicoValorDao)
        {
            bool   _resultado = false;
            string _msg       = "";

            using (SqlConnection connection = new SqlConnection(strConnSql))
            {
                connection.Open();

                SqlCommand     command = connection.CreateCommand();
                SqlTransaction transaction;

                // Start a local transaction.
                transaction = connection.BeginTransaction("AtualizarValorEvento");

                command.Connection  = connection;
                command.Transaction = transaction;

                try
                {
                    // Atualizando os dados na tabela:

                    command.CommandText = "" +
                                          "UPDATE dbo.AD_Valor_Evento_Publico " +
                                          "SET Valor = @Valor, Ativo = @Ativo " +
                                          "WHERE ValorEventoPublicoId = @id";

                    command.Parameters.AddWithValue("Valor", tipoPublicoValorDao.Valor);
                    command.Parameters.AddWithValue("Ativo", tipoPublicoValorDao.ValorAtivo);
                    command.Parameters.AddWithValue("id", id);

                    int i = command.ExecuteNonQuery();
                    _resultado = i > 0;

                    _msg = _resultado ? "Atualização Realizada com sucesso" : "Atualização NÃO Realizada com sucesso";

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    try
                    {
                        transaction.Rollback();
                    }
                    catch (Exception ex2)
                    {
                        throw new Exception($"Rollback Exception Type:{ex2.GetType()}. Erro:{ex2.Message}");
                    }
                    throw new Exception($"Commit Exception Type:{ex.GetType()}. Erro:{ex.Message}");
                }
                finally
                {
                    connection.Close();
                }
            }
            return(_msg);
        }
示例#3
0
 public string UpdateValorEvento(int id, TipoPublicoValorDao tipoPublicoValorDao)
 {
     return(_eventoRepository.UpdateValorEvento(id, tipoPublicoValorDao));
 }
示例#4
0
 public string InsertValorEvento(TipoPublicoValorDao tipoPublicoValorDao)
 {
     return(_eventoRepository.InsertValorEvento(tipoPublicoValorDao));
 }