public IActionResult GetHistoric(int id) { string sql = $"SELECT * from historicoSalarios WHERE id = {id}"; HistoricoSalarios historicoSalarios = new HistoricoSalarios(); try { using (SqlConnection cnn = new SqlConnection(AfaDB.cnnString)) { using (SqlCommand cmd = new SqlCommand(sql, cnn)) { SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { historicoSalarios.id = dr.GetFieldValue <int>(dr.GetOrdinal("id")); historicoSalarios.clubId = dr.GetFieldValue <int>(dr.GetOrdinal("clubId")); historicoSalarios.jugadorId = dr.GetFieldValue <int>(dr.GetOrdinal("jugadorId")); historicoSalarios.año = dr.GetFieldValue <int>(dr.GetOrdinal("año")); historicoSalarios.salarioPrm = dr.GetFieldValue <double>(dr.GetOrdinal("salarioPrm")); } } return(new OkObjectResult(historicoSalarios)); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(new NotFoundResult()); } }
public void ExcluirHistoricoSalario(int Id) { if (Id > 0) { HistoricoSalarios historicosalarios = repositorioSalarios.PesquisarPorId(Id); repositorioSalarios.Excluir(historicosalarios); } }
public void EditarFalta(HistoricoSalarios historicosalarios) { if (historicosalarios != null) { HistoricoSalarios local = repositorioSalarios.PesquisarPorId(historicosalarios.Id); local.Salario = historicosalarios.Salario; local.DataPagamento = historicosalarios.DataPagamento; local.IdFuncionario = historicosalarios.IdFuncionario; repositorioSalarios.Atualizar(local); } }
public HistoricoSalarios Inserir(HistoricoSalarios historicoDeSalario) { historicoDeSalario.DataInclusao = DateTime.Now; try { return(repositorioSalarios.Inserir(historicoDeSalario)); } catch (Exception) { return(null); } }
public IActionResult Post(HistoricoSalarios historicoSalarios) { string sql = $"INSERT INTO historicoSalarios (id, clubId, jugadorId, año, salarioPrm)"; sql += "VALUES(@id, @clubId, @jugadorId, @año, @salarioPrm)"; try { using (SqlConnection cnn = new SqlConnection(AfaDB.cnnString)) { using (SqlTransaction trn = cnn.BeginTransaction()) { try { using (SqlCommand cmd = new SqlCommand(sql, cnn)) { cmd.Transaction = trn; cmd.Parameters.Add(new SqlParameter("@id", historicoSalarios.id)); cmd.Parameters.Add(new SqlParameter("@nombre", historicoSalarios.clubId)); cmd.Parameters.Add(new SqlParameter("@ciudad", historicoSalarios.jugadorId)); cmd.Parameters.Add(new SqlParameter("@provincia", historicoSalarios.año)); cmd.Parameters.Add(new SqlParameter("@fundacion", historicoSalarios.salarioPrm)); var rowsAffected = cmd.ExecuteNonQuery(); trn.Commit(); return(new OkObjectResult(historicoSalarios)); } } catch (Exception ex) { trn.Rollback(); Console.WriteLine(ex.StackTrace); return(new NotFoundResult()); } } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(new NotFoundResult()); } }
public HistoricoSalarios PesquisarPorId(int Id) { if (Id > 0) { try { HistoricoSalarios falta = repositorioSalarios.PesquisarPorId(Id); return(falta); } catch (Exception) { return(null); } } else { return(null); } }
public IActionResult Update(HistoricoSalarios historicoSalarios, int id) { string sql = $"UPDATE historicoSalarios SET clubId = {historicoSalarios.clubId}, jugadorId = {historicoSalarios.jugadorId}, año = {historicoSalarios.año}, salarioPrm = {historicoSalarios.salarioPrm}"; try { using (SqlConnection cnn = new SqlConnection(AfaDB.cnnString)) { using (SqlCommand cmd = new SqlCommand(sql, cnn)) { cmd.ExecuteNonQuery(); return(new OkObjectResult(historicoSalarios)); } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(new NotFoundResult()); } }