Skip to content

Instantly share code, notes, and snippets.

@hidegh
Created September 3, 2016 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidegh/1f347ce8eb08f77befe61351bc1208d6 to your computer and use it in GitHub Desktop.
Save hidegh/1f347ce8eb08f77befe61351bc1208d6 to your computer and use it in GitHub Desktop.
public IHttpActionResult SavePhoneSystems(long waiverId, IList<PhoneSystemModel> model)
{
var waiver = ReturnUnfinishedWaiverByIdForUser(waiverId);
// Save phone systems (with addresses)
using (var tx = TransactionScopeBuilder.New())
{
waiver.SetPhoneSystems(model);
waiver.MarkAsDataCompletelyEntered();
DbContext.SaveChanges();
tx.Complete();
}
// NOTE:
// We use 2 transactions for a good reason.
// We have separate state for all data entered and saved and for forms generated.
// By doing 2 transactions, we ensure that a timeout - that might occure by the longer lasting form generation -...
// ...won't roll back data the user already entered (and out logic saved).
//
// If the process below would take much more time than 2-5 secs, messaging systems like Hangfire.io, NServiceBus shold be used.
// Do generate new form...
using (var tx = TransactionScopeBuilder.New(timeout: TimeSpan.FromSeconds(60)))
{
if (waiver.IsReviewNeeded)
{
WaiverFormsGenerator.CreateDocumentsFor(waiver);
}
DbContext.SaveChanges();
tx.Complete();
}
// Success
return Ok();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment