To elaborate on this subject, you have several choices. Some of them have already been elaborated upon. The following approaches exists, Add, AddWithValue, and an entire parameter collection. This provides flexibility, but also you mention to return a value.
So to approach the initial parameter aspect.
Add: You define the parameter, the type in SQL, and value. This alleviates potential database inference issues. You pass a value which is an integer but SQL believes it should be a decimal as defined.
AddWithValue: SQL will auto infer the type, simply pass a value and parameter.
Parameter Collection: You define all of your parameters in advance, then simply pass to your SqlCommand.
A sample method would be:
public class DatabaseContext : IDbRepository
{
private readonly string dbConnection;
public DatabaseContext(IConfiguration configuration) => dbConnection = configuration.GetConnectionString("dbConnection");
public bool Insert(string query, params SqlParameter[] parameters)
{
// If no parameters, then you really are not inserting. Handle exception.
using(var connection = new SqlConnection(dbConnection))
using(var command = new SqlCommand(connection, query))
{
connection.Open();
command.Parameters.AddRange(parameters);
return (command.ExecuteNonQuery() > 0);
}
}
So in essence you would call your context, pass the query, the parameters, then execute your query. But you have it returning a boolean, rather than a conditional check to assign a success or failure. When you call, you would know it succeeded, so you could pass a valid status code back ie HttpStatusCode.Ok.
But you could also wrap in a factory, or clean the approach a bit when interacting. Hopefully this helps.