Exemplo n.º 1
0
        public void Handle(AnchorCreated @event)
        {
            using (var repository = this.contextFactory.Create())
            {
                var dto = DbContext.Find <AnchorType>(@event.SourceId);
                if (dto != null)
                {
                    logger.LogWarning(
                        "Ignoring AnchorCreated event for anchor type with ID {0} as it was already created.",
                        @event.SourceId);
                }
                else
                {
                    dto = new AnchorType(
                        @event.SourceId,
                        @event.WorkshopId,
                        @event.Name,
                        @event.Description,
                        @event.Price,
                        @event.Quantity);

                    bus.Send(
                        new AddAnchors
                    {
                        WorkshopID = @event.WorkshopId,
                        AnchorType = @event.SourceId,
                        Quantity   = @event.Quantity
                    });

                    DbContext.Save(dto);
                    repository.SaveChanges();
                }
            }
        }
        public void Handle(AnchorCreated @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();
            }
        }