Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.