public Event CreateEvent(JObject eventJson)
{
var eventName = eventJson.Properties().First().Name;
var eventBody = eventJson.Properties().First().Value.Value<JObject>();
switch(eventName)
{
case "CQRSMicroservices.Articles.ArticleCreatedEvent":
return new ArticleCreatedEvent
{
ArticleId = Guid.Parse(eventBody["ArticleId"].Value<string>()),
Description = eventBody["Description"].Value<string>(),
Price = decimal.Parse(eventBody["Price"].Value<string>(), CultureInfo.InvariantCulture)
};
case "CQRSMicroservices.Articles.ArticleAvailableEvent":
return new ArticleAvailableEvent
{
ArticleId = Guid.Parse(eventBody["ArticleId"].Value<string>()),
};
case "CQRSMicroservices.Articles.ArticleUnavailableEvent":
return new ArticleUnavailableEvent
{
ArticleId = Guid.Parse(eventBody["ArticleId"].Value<string>()),
};
case "CQRSMicroservices.Articles.ArticleSoldEvent":
return new ArticleSoldEvent
{
ArticleId = Guid.Parse(eventBody["ArticleId"].Value<string>()),
CustomerId = Guid.Parse(eventBody["CustomerId"].Value<string>()),
Price = decimal.Parse(eventBody["Price"].Value<string>(), CultureInfo.InvariantCulture)
};
case "CQRSMicroservices.Customers.CustomerCreatedEvent":
return new CustomerCreatedEvent
{
CustomerId = Guid.Parse(eventBody["CustomerId"].Value<string>()),
Name = eventBody["Name"].Value<string>()
};
default:
throw new EventNotFoundException(eventName);
}
}