public void Handle(SeatUpdated @event) { using (var repository = this.contextFactory.Invoke()) { var dto = repository.Find <SeatType>(@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; repository.Save(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(SeatUpdated @event) { using (var context = this.contextFactory.Invoke()) { var dto = context.Find <PricedOrderLineSeatTypeDescription>(@event.SourceId); if (dto == null) { dto = new PricedOrderLineSeatTypeDescription { SeatTypeId = @event.SourceId }; context.Set <PricedOrderLineSeatTypeDescription>().Add(dto); } dto.Name = @event.Name; context.SaveChanges(); } }
public void Handle(SeatUpdated @event) { using (var context = contextFactory.Invoke()) { var dto = context.Find <PricedOrderLineSeatTypeDescription>(@event.SourceId); if (dto == null) { dto = new PricedOrderLineSeatTypeDescription { SeatTypeId = @event.SourceId }; context.Set <PricedOrderLineSeatTypeDescription>().Add(dto); } dto.Name = @event.Name; context.SaveChanges(); seatDescriptionsCache.Set("SeatDescription_" + dto.SeatTypeId, dto, new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(5) }); } }
public void Handle(SeatUpdated @event) { using (var context = this._contextFactory.Invoke()) { var dto = context.Find <SeatType>(@event.SourceId); if (dto != null) { dto.Description = @event.Description; dto.Name = @event.Name; dto.Price = @event.Price; var diff = @event.Quantity - dto.Quantity; dto.Quantity = @event.Quantity; context.Save(dto); if (diff > 0) { this._commandBus.Send(new AddSeats() { ConferenceId = @event.ConferenceId, SeatType = @event.SourceId, Quantity = diff }); } else { this._commandBus.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(SeatUpdated @event) { this.innerGenerator.Handle(@event); }