public Response Update(ProductIncome productIncome) { Response response = new Response(); SqlConnection connection = new SqlConnection(); connection.ConnectionString = ConnectionHelper.GetConnectionString(); SqlCommand command = new SqlCommand(); command.CommandText = "UPDATE PRODUCTS_INCOME SET DATAENTRADA = @DATAENTRADA, IDFUNCIONARIO = @IDFUNCIONARIO, VALORTOTAL = @VALORTOTAL, IDFORNECEDOR = @IDFORNECEDOR WHERE ID = @ID"; command.Parameters.AddWithValue("@DATAENTRADA", productIncome.EntryDate); command.Parameters.AddWithValue("@IDFUNCIONARIO", productIncome.EmployeesID); command.Parameters.AddWithValue("@VALORTOTAL", productIncome.TotalValue); command.Parameters.AddWithValue("@IDFORNECEDOR", productIncome.SuppliersID); command.Parameters.AddWithValue("@ID", productIncome.ID); command.Connection = connection; try { connection.Open(); int nLinhasAfetadas = command.ExecuteNonQuery(); if (nLinhasAfetadas != 1) { response.Success = false; response.Message = "Registro não encontrado!"; return(response); } response.Success = true; response.Message = "Atualizado com sucesso."; } catch (Exception ex) { response.Success = false; response.Message = "Erro no banco de dados, contate o administrador."; response.StackTrace = ex.StackTrace; response.ExceptionError = ex.Message; } finally { connection.Close(); } return(response); }
public SingleResponse <int> Insert(ProductIncome productIncome) { SingleResponse <int> response = new SingleResponse <int>(); SqlConnection connection = new SqlConnection(); connection.ConnectionString = ConnectionHelper.GetConnectionString(); SqlCommand command = new SqlCommand(); command.CommandText = "INSERT INTO PRODUCTS_INCOME (DATAENTRADA, IDFUNCIONARIO, VALORTOTAL, IDFORNECEDOR) VALUES (@DATAENTRADA, @IDFUNCIONARIO, @VALORTOTAL, @IDFORNECEDOR) SELECT SCOPE_IDENTITY()"; command.Parameters.AddWithValue("@DATAENTRADA", productIncome.EntryDate); command.Parameters.AddWithValue("@IDFUNCIONARIO", productIncome.EmployeesID); command.Parameters.AddWithValue("@VALORTOTAL", productIncome.TotalValue); command.Parameters.AddWithValue("@IDFORNECEDOR", productIncome.SuppliersID); command.Connection = connection; try { connection.Open(); int idGerado = Convert.ToInt32(command.ExecuteScalar()); response.Success = true; response.Message = "Cadastrado com sucesso."; response.Data = idGerado; } catch (Exception ex) { response.Success = false; response.Message = "Erro no banco de dados, contate o administrador."; response.StackTrace = ex.StackTrace; response.ExceptionError = ex.Message; } finally { connection.Close(); } return(response); }