Created
January 31, 2014 10:13
-
-
Save udidahan/8729522 to your computer and use it in GitHub Desktop.
Refund policy for product returns
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 class RefundPolicy : Saga<RefundPolicy.State>, IAmStartedByMessages<OrderAccepted>, IHandleMessages<ProductsReturned>, | |
IHandleTimeouts<Percent>, | |
IHandleSagaNotFound | |
{ | |
public void Handle(OrderAccepted message) | |
{ | |
Data.OrderId = message.OrderId; | |
Data.Percent = 100; | |
RequestTimeout(TimeSpan.FromDays(30), 50.Percent()); | |
RequestTimeout(TimeSpan.FromDays(60), 0.Percent()); | |
} | |
public void Handle(ProductsReturned message) | |
{ | |
Bus.Send<IssueRefund>(r => r.Percent = Data.Percent); | |
MarkAsComplete(); | |
} | |
public void Timeout(Percent state) | |
{ | |
Data.Percent = state; | |
if (state.Val == 0) | |
MarkAsComplete(); | |
} | |
public void Handle(object message) | |
{ | |
if (message is ProductsReturned) | |
Console.WriteLine("No refund for you."); | |
} | |
public class State : ContainSagaData | |
{ | |
public Guid OrderId { get; set; } | |
public Percent Percent { get; set; } | |
} | |
public override void ConfigureHowToFindSaga() | |
{ | |
ConfigureMapping<ProductsReturned>(p => p.OrderId).ToSaga(s => s.OrderId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment