public void AddTemplate(Template template)
{
OpenConnection();
var binFormatter = new ListBinaryFormatter<string>();
_command.CommandText = "INSERT INTO Templates(Title, Data) VALUES(@Title, @Data)";
_command.Parameters.Add(GetParam("@Title", template.Title));
_command.Parameters.Add(GetParam("@Data", binFormatter.Serialize(template.Data)));
try
{
_command.ExecuteNonQuery();
//LOGGING
Logger.Info("Template was added");
}
catch (SqlException ex)
{
//LOGGING
Logger.Error("This template already exists!",ex);
throw new InvalidOperationException("This template already exists!");
}
catch (Exception ex)
{
//LOGGING
Logger.Error("Can't add template!",ex);
throw new InvalidOperationException("Can't add template!");
}
finally
{
CloseConnection();
}
}