示例#1
0
        public void Handle(AnchorUpdated @event)
        {
            using (var repository = this.contextFactory.Create())
            {
                var dto = DbContext.Find <AnchorType>(@event.SourceId);
                if (dto != null)
                {
                    dto.Description = @event.Description;
                    dto.Name        = @event.Name;
                    dto.Price       = @event.Price;

                    // Calculate diff to drive the anchor availability.
                    // Is it appropriate to have this here?
                    var diff = @event.Quantity - dto.Quantity;

                    dto.Quantity = @event.Quantity;

                    DbContext.Save(dto);

                    if (diff > 0)
                    {
                        this.bus.Send(
                            new AddAnchors
                        {
                            WorkshopID = @event.WorkshopID,
                            AnchorType = @event.SourceId,
                            Quantity   = diff,
                        });
                    }
                    else
                    {
                        bus.Send(
                            new AddAnchors
                        {
                            WorkshopID = @event.WorkshopID,
                            AnchorType = @event.SourceId,
                            Quantity   = Math.Abs(diff),
                        });
                    }

                    repository.SaveChanges();
                }
                else
                {
                    throw new InvalidOperationException(
                              string.Format("Failed to locate Anchor Type read model being updated with id {0}.", @event.SourceId));
                }
            }
        }
        public void Handle(AnchorUpdated @event)
        {
            using (var context = this.contextFactory.Create())
            {
                var dto = DbContext.Find <PricedOrderLineAnchorTypeDescription>(@event.SourceId);
                if (dto == null)
                {
                    dto = new PricedOrderLineAnchorTypeDescription {
                        SeatTypeID = @event.SourceId
                    };
                    DbContext.Set <PricedOrderLineAnchorTypeDescription>().Add(dto);
                }

                dto.Name = @event.Name;
                context.SaveChanges();
                this.seatDescriptionsCache.Set("SeatDescription_" + dto.SeatTypeID.ToString(), dto, DateTimeOffset.UtcNow.AddMinutes(5));
            }
        }