Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created April 4, 2016 21:52
Show Gist options
  • Save dcomartin/7a5fa30addc3deb51d0494abc3e6e53b to your computer and use it in GitHub Desktop.
Save dcomartin/7a5fa30addc3deb51d0494abc3e6e53b to your computer and use it in GitHub Desktop.
public class ChangeCustomerPricingLevel : IAsyncRequest
{
public Guid CustomerId { get; }
public PricingLevel PricingLevel { get; }
public ChangeCustomerPricingLevel(Guid customerId, PricingLevel pricingLevel)
{
CustomerId = customerId;
PricingLevel = pricingLevel;
}
}
public class ChangeCustomerPricingLevelHandler : IAsyncRequestHandler<Envelope<ChangeCustomerPricingLevel>, Unit>
{
private readonly CustomeRepository _repository;
public ChangeCustomerPricingLevelHandler(CustomeRepository repository)
{
_repository = repository;
}
public async Task<Unit> Handle(Envelope<ChangeCustomerPricingLevel> message)
{
var customer = _repository.Get(message.Body.CustomerId);
try
{
customer.SetOperation(message.MessageId);
}
catch (InvalidOperationException)
{
return Unit.Value;
}
customer.ChangePricingLevel(message.Body.PricingLevel);
_repository.Save(customer);
return Unit.Value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment