Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created April 18, 2016 22:57
Show Gist options
  • Save dcomartin/589116826bb05d337b38e2d6e0dc2893 to your computer and use it in GitHub Desktop.
Save dcomartin/589116826bb05d337b38e2d6e0dc2893 to your computer and use it in GitHub Desktop.
public class Handler : IAsyncRequestHandler<Envelope<Command>, Unit>
{
private readonly CustomeRepository _repository;
public Handler(CustomeRepository repository)
{
_repository = repository;
}
public async Task<Unit> Handle(Envelope<Command> message)
{
if (message.Body.CustomerId == Guid.Empty) throw new InvalidOperationException("CustomerId cannot be empty.");
var customer = _repository.Get(message.Body.CustomerId);
try
{
customer.SetOperation(message.MessageId);
}
catch (InvalidOperationException)
{
return Unit.Value;
}
customer.ChangePricingLevel(message.Body.PricingLevel);
await _repository.SaveAsync(customer);
return Unit.Value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment