public void Handle(OrderTotalsCalculated @event) { if (!ProcessOrder(order => order.Id == @event.SourceId, order => order.TotalAmount = @event.Total)) { logger.LogError("Failed to locate the order with id {0} to apply calculated totals", @event.SourceId); } }
public void Handle(OrderTotalsCalculated @event) { using (var context = this.contextFactory.Invoke()) { var dto = context.Find <DraftOrder>(@event.SourceId); if (WasNotAlreadyHandled(dto, @event.Version)) { dto.OrderVersion = @event.Version; context.Save(dto); } } }
public void when_order_expired_then_deletes_entity() { var e = new OrderTotalsCalculated { SourceId = placed.SourceId, Total = 10 }; sut.Handle(e); var order = FindOrder(e.SourceId); Assert.Equal(e.Total, order.TotalAmount); }
public void When_order_expired_then_deletes_entity() { var e = new OrderTotalsCalculated() { SourceId = _placed.SourceId, Total = 10 }; this._eventHandler.Handle(e); var order = this.FindOrder(e.SourceId); Assert.AreEqual(e.Total, order.TotalAmount); }
public void Handle(OrderTotalsCalculated @event) { var seatTypeIds = @event.Lines.OfType <SeatOrderLine>().Select(x => x.SeatType).Distinct().ToArray(); using (var context = this.contextFactory.Invoke()) { var dto = context.Query <PricedOrder>().Include(x => x.Lines).First(x => x.OrderId == @event.SourceId); if (!WasNotAlreadyHandled(dto, @event.Version)) { // message already handled, skip. return; } var linesSet = context.Set <PricedOrderLine>(); foreach (var line in dto.Lines.ToList()) { linesSet.Remove(line); } var seatTypeDescriptions = GetSeatTypeDescriptions(seatTypeIds, context); for (int i = 0; i < @event.Lines.Length; i++) { var orderLine = @event.Lines[i]; var line = new PricedOrderLine { LineTotal = orderLine.LineTotal, Position = i, }; var seatOrderLine = orderLine as SeatOrderLine; if (seatOrderLine != null) { // should we update the view model to avoid losing the SeatTypeId? line.Description = seatTypeDescriptions.Where(x => x.SeatTypeId == seatOrderLine.SeatType).Select(x => x.Name).FirstOrDefault(); line.UnitPrice = seatOrderLine.UnitPrice; line.Quantity = seatOrderLine.Quantity; } dto.Lines.Add(line); } dto.Total = @event.Total; dto.IsFreeOfCharge = @event.IsFreeOfCharge; dto.OrderVersion = @event.Version; context.SaveChanges(); } }
public void Handle(OrderTotalsCalculated @event) { var seatTypeIds = @event.Lines.OfType <SeatOrderLine>().Select(x => x.SeatType).Distinct().ToArray(); var dto = pricedOrderRepository.GetBy(x => x.OrderId == @event.SourceId).FirstOrDefault(); if (!WasNotAlreadyHandled(dto, @event.Version)) { // message already handled, skip. return; } //var seatTypeDescriptions = GetSeatTypeDescriptions(seatTypeIds, context); dto.Lines = new List <PricedOrderLine>(); for (int i = 0; i < @event.Lines.Length; i++) { var orderLine = @event.Lines[i]; var line = new PricedOrderLine { LineTotal = orderLine.LineTotal, Position = i, }; var seatOrderLine = orderLine as SeatOrderLine; if (seatOrderLine != null) { // should we update the view model to avoid losing the SeatTypeId? line.Description = seatTypeRepository.GetByKey(seatOrderLine.SeatType).Name; line.UnitPrice = seatOrderLine.UnitPrice; line.Quantity = seatOrderLine.Quantity; } dto.Lines.Add(line); } dto.Total = @event.Total; dto.IsFreeOfCharge = @event.IsFreeOfCharge; dto.OrderVersion = @event.Version; pricedOrderRepository.Update(dto); }
private void OnOrderTotalsCalculated(OrderTotalsCalculated e) { }