public DescontoAnuidadeAtc GetDescontoAnuidadeAtcById(int id) { List <DbParameter> _parametros = new List <DbParameter>(); // Definição do parâmetros da consulta: SqlParameter pid = new SqlParameter() { ParameterName = "@id", Value = id }; _parametros.Add(pid); // Fim da definição dos parâmetros query = @"SELECT DescontoAnuidadeAtcId, AssociadoId, ColaboradorId, AnuidadeId, AtcId, Observacao, NomeArquivoComprovante, DtDesconto, DtCadastro, Ativo FROM dbo.AD_Desconto_Anuidade_Atc WHERE DescontoAnuidadeAtcId= @id"; // Define o banco de dados que será usando: CommandSql cmd = new CommandSql(strConnSql, query, EnumDatabaseType.SqlServer, parametros: _parametros); // Obtém os dados do banco de dados: DescontoAnuidadeAtc desconto = GetCollection <DescontoAnuidadeAtc>(cmd)?.FirstOrDefault <DescontoAnuidadeAtc>(); // Log da consulta: string log = logRep.SetLogger(className + "/GetDescontoAnuidadeAtcById", "SELECT", "DESCONTO_ANUIDADE_ATC", id, query, desconto != null ? "SUCESSO" : "0"); // Fim Log return(desconto); }
public string Save(DescontoAnuidadeAtcDao d) { DescontoAnuidadeAtc _d = new DescontoAnuidadeAtc() { DescontoAnuidadeAtcId = d.DescontoAnuidadeAtcId, AssociadoId = d.AssociadoId, ColaboradorId = d.ColaboradorId, AnuidadeId = d.AnuidadeId, AtcId = d.AtcId, Observacao = Functions.AjustaTamanhoString(d.Observacao, 500), NomeArquivoComprovante = Functions.AjustaTamanhoString(d.NomeArquivoComprovante, 100), DtDesconto = d.DtDesconto, DtCadastro = d.DtCadastro, Ativo = d.Ativo }; try { if (_d.DescontoAnuidadeAtcId == 0) { return(_descontoAnuidadeAtcService.Insert(_d)); } else { return(_descontoAnuidadeAtcService.Update(_d.DescontoAnuidadeAtcId, _d)); } } catch (Exception ex) { throw ex; } }
public string Update(int id, DescontoAnuidadeAtc d) { 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("AtualizarDescontoAnuidadeAtc"); command.Connection = connection; command.Transaction = transaction; try { command.CommandText = "" + "UPDATE dbo.AD_Desconto_Anuidade_Atc " + "SET Observacao = @Observacao, NomeArquivoComprovante = @NomeArquivoComprovante, " + " Ativo = @Ativo " + "WHERE DescontoAnuidadeAtcId = @id"; command.Parameters.AddWithValue("Observacao", d.Observacao); command.Parameters.AddWithValue("NomeArquivoComprovante", d.NomeArquivoComprovante); command.Parameters.AddWithValue("Ativo", d.Ativo); command.Parameters.AddWithValue("id", id); int x = command.ExecuteNonQuery(); _resultado = x > 0; _msg = x > 0 ? "Atualização realizada com sucesso" : "Atualização NÃO realizada com sucesso"; transaction.Commit(); // Log do UPDATE ANUIDADE: StringBuilder sb = new StringBuilder(); sb.Append("Parâmetros: "); for (int z = 0; z < command.Parameters.Count; z++) { sb.Append(command.Parameters[z].ParameterName + ": " + command.Parameters[z].Value + ", "); } _instrucaoSql = sb.ToString(); _result = x > 0 ? "SUCESSO" : "FALHA"; string log = logRep.SetLogger(className + "/Update", "UPDATE", "DESCONTO_ANUIDADE_ATC", id, _instrucaoSql, _result); //Fim do Log } catch (Exception ex) { try { transaction.Rollback(); } catch (Exception ex2) { _msg = $"ATENÇÃO: Ocorreu um erro ao tentar ATUALIZAR DESCONTO_ANUIDADE_ATC: Commit Exception Type:{ex2.GetType()}. Erro:{ex2.Message}"; // throw new Exception($"Rollback Exception Type:{ex2.GetType()}. Erro:{ex2.Message}"); } string log = logRep.SetLogger(className + "/Update", "UPDATE", "DESCONTO_ANUIDADE_ATC", 0, ex.Message, "FALHA"); _msg = $"ATENÇÃO: Ocorreu um erro ao tentar ATUALIZAR DESCONTO_ANUIDADE_ATC: Commit Exception Type:{ex.GetType()}. Erro:{ex.Message}"; // throw new Exception($"Commit Exception Type:{ex.GetType()}. Erro:{ex.Message}"); } finally { connection.Close(); } } return(_msg); }
public string Insert(DescontoAnuidadeAtc d) { bool _resultado = false; string _msg = ""; Int32 id = 0; string _ident = ""; using (SqlConnection connection = new SqlConnection(strConnSql)) { connection.Open(); SqlCommand command = connection.CreateCommand(); SqlTransaction transaction; // Start a local transaction. transaction = connection.BeginTransaction("IncluirDescontoAnuidadeAtc"); command.Connection = connection; command.Transaction = transaction; try { command.CommandText = "" + "INSERT into dbo.AD_Desconto_Anuidade_Atc (AssociadoId, ColaboradorId, " + " AnuidadeId, AtcId, Observacao, NomeArquivoComprovante, " + " DtDesconto, DtCadastro, Ativo) " + "VALUES (@AssociadoId, @ColaboradorId, " + " @AnuidadeId, @AtcId, @Observacao, @NomeArquivoComprovante, " + " @DtDesconto, @DtCadastro, @Ativo) " + "SELECT CAST(scope_identity() AS int) "; command.Parameters.AddWithValue("AssociadoId", d.AssociadoId); command.Parameters.AddWithValue("ColaboradorId", d.ColaboradorId); command.Parameters.AddWithValue("AnuidadeId", d.AnuidadeId); command.Parameters.AddWithValue("AtcId", d.AtcId); command.Parameters.AddWithValue("Observacao", d.Observacao); command.Parameters.AddWithValue("NomeArquivoComprovante", d.NomeArquivoComprovante); command.Parameters.AddWithValue("DtDesconto", DateTime.Now); command.Parameters.AddWithValue("DtCadastro", DateTime.Now); command.Parameters.AddWithValue("Ativo", d.Ativo); id = (Int32)command.ExecuteScalar(); _resultado = id > 0; if (id > 0) { _ident = _ident.PadLeft(10 - id.ToString().Length, '0') + id.ToString(); } _msg = id > 0 ? $"{_ident}Inclusão realizada com sucesso" : $"{_ident}Inclusão Não realizada com sucesso"; transaction.Commit(); // Log da Inserção ANUIDADE: StringBuilder sb = new StringBuilder(); sb.Append("Parâmetros: "); for (int z = 0; z < command.Parameters.Count; z++) { sb.Append(command.Parameters[z].ParameterName + ": " + command.Parameters[z].Value + ", "); } _instrucaoSql = sb.ToString(); _result = id > 0 ? "SUCESSO" : "FALHA"; string log = logRep.SetLogger(className + "/Insert", "INSERT", "DESCONTO_ANUIDADE_ATC", id, _instrucaoSql, _result); //Fim do Log } catch (Exception ex) { // Attempt to roll back the transaction. try { transaction.Rollback(); } catch (Exception ex2) { _msg = $"ATENÇÃO: Ocorreu um erro ao tentar INCLUIR DESCONTO_ANUIDADE_ATC: Commit Exception Type:{ex2.GetType()}. Erro:{ex2.Message}"; //throw new Exception($"Rollback Exception Type:{ex2.GetType()}. Erro:{ex2.Message}"); } string log = logRep.SetLogger(className + "/Insert", "INSERT", "DESCONTO_ANUIDADE_ATC", 0, ex.Message, "FALHA"); _msg = $"ATENÇÃO: Ocorreu um erro ao tentar INCLUIR DESCONTO_ANUIDADE_ATC: Commit Exception Type:{ex.GetType()}. Erro:{ex.Message}"; // throw new Exception($"Commit Exception Type:{ex.GetType()}. Erro:{ex.Message}"); } finally { connection.Close(); } } return(_msg); }
public string Update(int id, DescontoAnuidadeAtc descontoAnuidadeAtc) { return(_descontoAnuidadeAtcRepository.Update(id, descontoAnuidadeAtc)); }
public string Insert(DescontoAnuidadeAtc descontoAnuidadeAtc) { return(_descontoAnuidadeAtcRepository.Insert(descontoAnuidadeAtc)); }