Пример #1
0
        public void UpdateSeat(Guid conferenceId, SeatType seat)
        {
            using (var context = new ConferenceContext()) {
                var existing = context.Seats.Find(seat.Id);
                if (existing == null)
                {
                    throw new ObjectNotFoundException();
                }

                context.Entry(existing).CurrentValues.SetValues(seat);
                context.SaveChanges();

                // Don't publish seat updates if the conference was never published
                // (and therefore is not published either).
                if (context.Conferences.Where(x => x.Id == conferenceId).Select(x => x.WasEverPublished).FirstOrDefault())
                {
                    eventBus.Publish(new SeatUpdated {
                        ConferenceId = conferenceId,
                        SourceId     = seat.Id,
                        Name         = seat.Name,
                        Description  = seat.Description,
                        Price        = seat.Price,
                        Quantity     = seat.Quantity
                    });
                }
            }
        }
        public void UpdateSeat(Guid conferenceId, SeatType seat)
        {
            using (ConferenceContext context = new ConferenceContext(this._nameOrConnectionString)) {
                SeatType existing = context.Seats.Find(seat.Id);

                if (existing == null)
                {
                    throw new ObjectNotFoundException();
                }

                context.Entry(existing).CurrentValues.SetValues(seat);

                context.SaveChanges();

                if (context.Conferences.Where(x => x.Id == conferenceId).Select(x => x.WasEverPublished).FirstOrDefault())
                {
                    this._eventBus.Publish(new SeatUpdated()
                    {
                        ConferenceId = conferenceId,
                        SourceId     = seat.Id,
                        Name         = seat.Name,
                        Description  = seat.Description,
                        Price        = seat.Price,
                        Quantity     = seat.Quantity
                    });
                }
            }
        }
Пример #3
0
 private void PublishSeatCreated(Guid conferenceId, SeatType seat)
 {
     eventBus.Publish(new SeatCreated {
         ConferenceId = conferenceId,
         SourceId     = seat.Id,
         Name         = seat.Name,
         Description  = seat.Description,
         Price        = seat.Price,
         Quantity     = seat.Quantity
     });
 }
Пример #4
0
        public void CreateSeat(Guid conferenceId, SeatType seat)
        {
            using (var context = new ConferenceContext()) {
                var conference = context.Conferences.Find(conferenceId);
                if (conference == null)
                {
                    throw new ObjectNotFoundException();
                }

                conference.Seats.Add(seat);
                context.SaveChanges();

                // Don't publish new seats if the conference was never published
                // (and therefore is not published either).
                if (conference.WasEverPublished)
                {
                    PublishSeatCreated(conferenceId, seat);
                }
            }
        }
        /// <summary>
        /// 创建座位
        /// </summary>
        /// <param name="conferenceId"></param>
        /// <param name="seat"></param>
        public void CreateSeat(Guid conferenceId, SeatType seat)
        {
            using (ConferenceContext context = new ConferenceContext(this._nameOrConnectionString)) {
                var conference = context.Conferences.Find(conferenceId);

                if (conference == null)
                {
                    throw new ObjectNotFoundException();
                }

                conference.Seats.Add(seat);

                context.SaveChanges();

                if (conference.WasEverPublished)
                {
                    this.PublishSeatCreated(conferenceId, seat);
                }
            }
        }
Пример #6
0
        public void CreateSeat(Guid conferenceId, SeatType seat)
        {
            using (var context = new ConferenceContext(this.nameOrConnectionString))
            {
                var conference = this.retryPolicy.ExecuteAction(() => context.Conferences.Find(conferenceId));
                if (conference == null)
                {
                    throw new ObjectNotFoundException();
                }

                conference.Seats.Add(seat);
                this.retryPolicy.ExecuteAction(() => context.SaveChanges());

                // Don't publish new seats if the conference was never published
                // (and therefore is not published either).
                if (conference.WasEverPublished)
                {
                    this.PublishSeatCreated(conferenceId, seat);
                }
            }
        }
        public void DeleteSeat(Guid id)
        {
            using (ConferenceContext context = new ConferenceContext(this._nameOrConnectionString)) {
                SeatType seat = context.Seats.Find(id);
                if (seat == null)
                {
                    throw new ObjectNotFoundException();
                }

                bool wasPublished = context.Conferences.Where(x => x.Seats.Any(s => s.Id == id))
                                    .Select(x => x.WasEverPublished)
                                    .FirstOrDefault();

                if (wasPublished)
                {
                    throw new InvalidOperationException(
                              "Can't delete seats from a conference that has been published at least once.");
                }

                context.Seats.Remove(seat);

                context.SaveChanges();
            }
        }