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
                    });
                }
            }
        }
        public void CreateConference(ConferenceInfo conference)
        {
            using (var context = new ConferenceContext()) {
                var existingSlug =
                    context.Conferences
                    .Where(c => c.Slug == conference.Slug)
                    .Select(c => c.Slug)
                    .Any();

                if (existingSlug)
                {
                    throw new DuplicateNameException("The chosen conference slug is already taken.");
                }

                // Conference publishing is explicit.
                if (conference.IsPublished)
                {
                    conference.IsPublished = false;
                }

                context.Conferences.Add(conference);
                context.SaveChanges();

                PublishConferenceEvent <ConferenceCreated>(conference);
            }
        }
        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
                    });
                }
            }
        }
Exemple #4
0
        private void UpdatePublished(Guid conferenceId, bool isPublished)
        {
            using (var context = new ConferenceContext(this.nameOrConnectionString))
            {
                var conference = this.retryPolicy.ExecuteAction(() => context.Conferences.Find(conferenceId));
                if (conference == null)
                {
                    throw new ObjectNotFoundException();
                }

                conference.IsPublished = isPublished;
                if (isPublished && !conference.WasEverPublished)
                {
                    // This flags prevents any further seat type deletions.
                    conference.WasEverPublished = true;
                    this.retryPolicy.ExecuteAction(() => context.SaveChanges());

                    // We always publish events *after* saving to store.
                    // Publish all seats that were created before.
                    foreach (var seat in conference.Seats)
                    {
                        PublishSeatCreated(conference.Id, seat);
                    }
                }
                else
                {
                    this.retryPolicy.ExecuteAction(() => context.SaveChanges());
                }

                if (isPublished)
                {
                    this.eventBus.Publish(new ConferencePublished {
                        SourceId = conferenceId
                    });
                }
                else
                {
                    this.eventBus.Publish(new ConferenceUnpublished {
                        SourceId = conferenceId
                    });
                }
            }
        }
        private void UpdatePublished(Guid conferenceId, bool isPublished)
        {
            using (ConferenceContext context = new ConferenceContext(this._nameOrConnectionString)) {
                ConferenceInfo conference = context.Conferences.Find(conferenceId);
                if (conference == null)
                {
                    throw new ObjectNotFoundException();
                }

                conference.IsPublished = isPublished;
                if (isPublished && !conference.WasEverPublished)
                {
                    conference.WasEverPublished = true;
                    context.SaveChanges();

                    foreach (SeatType seat in conference.Seats)
                    {
                        this.PublishSeatCreated(conference.Id, seat);
                    }
                }
                else
                {
                    context.SaveChanges();
                }

                if (isPublished)
                {
                    this._eventBus.Publish(new ConferencePublished()
                    {
                        SourceId = conferenceId
                    });
                }
                else
                {
                    this._eventBus.Publish(new ConferenceUnpublished()
                    {
                        SourceId = conferenceId
                    });
                }
            }
        }
        public void UpdateConference(ConferenceInfo conference)
        {
            using (var context = new ConferenceContext()) {
                var existing = context.Conferences.Find(conference.Id);
                if (existing == null)
                {
                    throw new ObjectNotFoundException();
                }

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

                PublishConferenceEvent <ConferenceUpdated>(conference);
            }
        }
Exemple #7
0
        public void UpdateConference(ConferenceInfo conference)
        {
            using (var context = new ConferenceContext(this.nameOrConnectionString))
            {
                var existing = this.retryPolicy.ExecuteAction(() => context.Conferences.Find(conference.Id));
                if (existing == null)
                {
                    throw new ObjectNotFoundException();
                }

                context.Entry(existing).CurrentValues.SetValues(conference);
                this.retryPolicy.ExecuteAction(() => context.SaveChanges());

                this.PublishConferenceEvent <ConferenceUpdated>(conference);
            }
        }
        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);
                }
            }
        }
Exemple #10
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 (var context = new ConferenceContext()) {
                var seat = context.Seats.Find(id);
                if (seat == null)
                {
                    throw new ObjectNotFoundException();
                }

                var 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();
            }
        }
        /// <summary>
        /// 创建会议
        /// </summary>
        /// <param name="conference"></param>
        public void CreateConference(ConferenceInfo conference)
        {
            using (ConferenceContext context = new ConferenceContext(this._nameOrConnectionString)) {
                bool existingSlug = context.Conferences.Where(c => c.Slug == conference.Slug)
                                    .Select(c => c.Slug).Any();

                if (existingSlug)
                {
                    throw new DuplicateNameException("The chosen conference slug is already taken.");
                }

                if (conference.IsPublished)
                {
                    conference.IsPublished = false;
                }

                context.Conferences.Add(conference);

                context.SaveChanges();

                this.PublishConferenceEvent <ConferenceCreated>(conference);
            }
        }