Created
September 3, 2016 07:42
-
-
Save hidegh/1f347ce8eb08f77befe61351bc1208d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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