Skip to content

Instantly share code, notes, and snippets.

@udidahan
Created January 31, 2014 10:13
Show Gist options
  • Save udidahan/8729522 to your computer and use it in GitHub Desktop.
Save udidahan/8729522 to your computer and use it in GitHub Desktop.
Refund policy for product returns
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