public void Handle(SeatAssigned @event) { var dto = Find(@event.SourceId); var seat = dto.Seats.First(x => x.Position == @event.Position); Mapper.Map(@event, seat); orderSeatsRepository.Update(dto); }
public void Handle(OrderRegistrantAssigned @event) { var dto = GetDraftOrder(@event.SourceId); if (WasNotAlreadyHandled(dto, @event.Version)) { dto.RegistrantEmail = @event.Email; dto.OrderVersion = @event.Version; draftOrderRepository.Update(dto); } }
public void Handle(SeatUpdated @event) { var dto = GetSeatTypeView(@event.SourceId); if (dto != null) { dto.Description = @event.Description; dto.Name = @event.Name; dto.Price = @event.Price; // Calculate diff to drive the seat availability. // Is it appropriate to have this here? var diff = @event.Quantity - dto.Quantity; dto.Quantity = @event.Quantity; seatTypeRepository.Update(dto); if (diff > 0) { this.bus.Send( new AddSeats { ConferenceId = @event.ConferenceId, SeatType = @event.SourceId, Quantity = diff, }); } else { this.bus.Send( new RemoveSeats { ConferenceId = @event.ConferenceId, SeatType = @event.SourceId, Quantity = Math.Abs(diff), }); } } else { throw new InvalidOperationException( string.Format("Failed to locate Seat Type read model being updated with id {0}.", @event.SourceId)); } }
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); }
public void Handle(ConferenceUpdated @event) { var dto = GetConferenceView(@event.SourceId); if (dto != null) { dto.Code = @event.Slug; dto.Description = @event.Description; dto.Location = @event.Location; dto.Name = @event.Name; dto.StartDate = @event.StartDate; dto.Tagline = @event.Tagline; dto.TwitterSearch = @event.TwitterSearch; conferenceRepository.Update(dto); } else { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Failed to locate Conference read model for updated conference with id {0}.", @event.SourceId)); } }