Created
April 4, 2016 21:52
-
-
Save dcomartin/7a5fa30addc3deb51d0494abc3e6e53b 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 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