laatzen/LaaProductionWeb/LaaProductionWeb.Data/SqlParameters.cs
Stoyan Zlatev cf9dfe1915 Production Approvals,
sql client refactoring
2023-04-14 16:45:41 +02:00

45 lines
1.2 KiB
C#

namespace LaaProductionWeb.Data
{
using LaaProductionWeb.Data.Interfaces;
using System;
using System.Data;
using System.Data.SqlClient;
public class SqlParameters : ISqlParameters
{
private readonly SqlParameterCollection parameters;
private SqlParameters(SqlParameterCollection parameters)
=> this.parameters = parameters;
public ISqlParameters Add(string name, object value)
{
this.parameters.Add(new SqlParameter(name, value ?? DBNull.Value));
return this;
}
public ISqlParameters AddFile(string name, byte[] fileContent)
{
var sqlParameter = new SqlParameter(name, SqlDbType.VarBinary);
if (fileContent is null)
{
sqlParameter.Value = DBNull.Value;
}
else
{
sqlParameter.Value = fileContent;
}
this.parameters.Add(sqlParameter);
return this;
}
public static implicit operator SqlParameters(SqlParameterCollection sqlParameterCollection)
=> new SqlParameters(sqlParameterCollection);
}
}