Skip to content

Instantly share code, notes, and snippets.

@explorer14
Created August 22, 2019 18:57
Show Gist options
  • Save explorer14/71f7c4b716754bd01954b43bc4f7b0e5 to your computer and use it in GitHub Desktop.
Save explorer14/71f7c4b716754bd01954b43bc4f7b0e5 to your computer and use it in GitHub Desktop.
namespace Domain.ProductInformation.EventHandlers
{
public class ProductInformationHandler :
IHandleEvents<ProductInformation>
{
private readonly ReviewUsecase _reviewUseCase;
private readonly IStorePurchaseOrders _purchaseOrderStore;
private readonly IStoreProducts _productStore;
public ProductInformationHandler(
ReviewUsecase reviewUseCase,
IStorePurchaseOrders purchaseOrderStore,
IStoreProducts productStore)
{
_reviewUseCase = reviewUseCase;
_purchaseOrderStore = purchaseOrderStore;
_productStore = productStore;
}
public async Task Handle(ProductInformation eventToHandle)
{
var product = eventToHandle.ToEntity();
await _productStore.Save();
var purchaseOrderItems = await _purchaseOrderStore
.GetFor(eventToHandle.ProductId);
foreach (var item in purchaseOrderItems)
{
await _reviewUseCase.Execute(item, product);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment