public void UpdateProjection(Order.Delivered @event) { using (var db = new OrderHistoryDbContext()) { var entry = db.Orders.Single(o => o.OrderId == @event.AggregateId); entry.DeliveredOn = new DateTime(@event.Timestamp.Ticks); db.SaveChanges(); } }
public void a_history_read_model_should_be_available_reflecting_the_order_ship_date() { using (api.EventBus.Subscribe(new UpdateOrderHistory())) { api.EventBus.PublishAsync(order.EventHistory.ToArray()).Wait(); using (var db = new OrderHistoryDbContext()) { var entry = db.Orders.Single(o => o.OrderId == order.Id); var orderShippedOn = order.EventHistory.OfType <Order.Shipped>().Single().TimeStamp.Date; var readModelShippedOn = entry.ShippedOn.Value.Date; readModelShippedOn.Should().Be(orderShippedOn); } } }
public void UpdateProjection(Order.Placed @event) { using (var db = new OrderHistoryDbContext()) { var entry = new OrderHistoryEntry { CustomerId = @event.CustomerId, OrderId = @event.AggregateId, OrderNumber = @event.OrderNumber, TotalPrice = @event.TotalPrice, Items = new List <OrderHistoryItem>(@event.Items.Select(i => new OrderHistoryItem { Id = Guid.NewGuid(), Price = i.Price, ProductName = i.ProductName, Quantity = i.Quantity })), PlacedOn = new DateTime(@event.Timestamp.Ticks) }; db.Orders.AddOrUpdate(entry); db.SaveChanges(); } }
public OrderHistoryService(OrderHistoryDbContext context, IMapper mapper) { _context = context; _mapper = mapper; }