Skip to content

Instantly share code, notes, and snippets.

@haroldcris
Created March 1, 2017 23:53
Show Gist options
  • Save haroldcris/d2c4351528f0b10612a4c477fadf852f to your computer and use it in GitHub Desktop.
Save haroldcris/d2c4351528f0b10612a4c477fadf852f to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>CrudSave</Title>
<Shortcut>crudsave</Shortcut>
<Description>Code snippet for Basic Saving</Description>
<Author>AiTech Solutions</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>expression</ID>
<ToolTip>Name of Method</ToolTip>
<Default>MyFunctionName</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[var result = 0;
var db = new SqlConnection();
if (hasOwnDbConnection)
db = DbConnection;
else
db = Connection.CreateConnection();
try
{
result += ExecuteDeleteQuery(db);
result += ExecuteUpdateQuery(db);
result += ExecuteInsertQuery(db);
return result != 0;
}
catch (Exception ex)
{
throw new Exception("Error Saving $expression$", ex);
}
finally
{
if (!hasOwnDbConnection)
{
db.Close();db.Dispose();
}
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment