public async Task UpdateTitle(string id, string title) { var @event = await CreateEvent(id, EventTypes.TitleUpdated, title); var titleUpdated = TitleUpdated.Create(@event, id, title); messageQueue.Publish(titleUpdated); }
IMessage <object> ConstructMessage <T>(Event @event) { var data = @event.Data; if (data == null) { throw new ArgumentNullException(nameof(@event.Data)); } switch (data.Type) { case EventTypes.AmountUpdated: var amount = data.Payload as int?; if (amount != null) { return((IMessage <object>)AmountUpdated.Create(@event, data.Id, amount.Value)); } break; case EventTypes.ProductCreated: if (data.Payload is Product product) { return((IMessage <object>)ProductCreated.Create(@event, product)); } break; case EventTypes.ProductDeleted: return((IMessage <object>)ProductDeleted.Create(@event, data.Id)); case EventTypes.TitleUpdated: var title = data.Payload as string; return((IMessage <object>)TitleUpdated.Create(@event, data.Id, title)); default: break; } throw new ArgumentException($"InvalidEvent data: {data.Id}, " + $"{data.Type}, {data.Payload}"); }