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 }); } } }
// // public async Task<IEnumerable<SeatType>> FindSeatTypes(Guid conferenceId) // { // return await this.retryPolicy.ExecuteAsync(async () => await // context.Conferences // .Include(x => x.Seats) // .Where(x => x.Id == conferenceId) // .Select(x => x.Seats) // .FirstOrDefaultAsync()) ?? // Enumerable.Empty<SeatType>(); // } // // public async Task<SeatType> FindSeatType(Guid seatTypeId) // { // return await this.retryPolicy.ExecuteAsync(async () => await context.Seats.FindAsync(seatTypeId)); // } // // public async Task<IEnumerable<Order>> FindOrders(Guid conferenceId) // { // return await this.retryPolicy.ExecuteAsync(async () =>await context.Orders.Include("Seats.SeatInfo") // .Where(x => x.ConferenceId == conferenceId) // .ToListAsync()); // } public async Task UpdateConference(ConferenceInfo conference) { var existing = await this.retryPolicy.ExecuteAsync(async() => await context.Conferences.FindAsync(conference.Id)); if (existing == null) { throw new Exception(); //ObjectNotFoundException } context.Entry(existing).CurrentValues.SetValues(conference); await this.retryPolicy.ExecuteAsync(async() => await context.SaveChangesAsync()); await this.PublishConferenceEvent <ConferenceUpdated>(conference); }
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); } }
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); } }