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 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); } }
private void PublishConferenceEvent <T>(ConferenceInfo conference) where T : ConferenceEvent, new() { eventBus.Publish(new T { SourceId = conference.Id, Owner = new Owner { Name = conference.OwnerName, Email = conference.OwnerEmail }, Name = conference.Name, Description = conference.Description, Location = conference.Location, Slug = conference.Slug, Tagline = conference.Tagline, TwitterSearch = conference.TwitterSearch, StartDate = conference.StartDate, EndDate = conference.EndDate }); }
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 async Task DeleteSeat(Guid id) // { // var seat = await this.retryPolicy.ExecuteAsync(async () =>await context.Seats.FindAsync(id)); // if (seat == null) // throw new Exception(); //TODO: ObjectNotFoundException // // var wasPublished = await this.retryPolicy.ExecuteAsync(async () =>await context.Conferences // .Where(x => x.Seats.Any(s => s.Id == id)) // .Select(x => x.WasEverPublished) // .FirstOrDefaultAsync()); // // if (wasPublished) // throw new InvalidOperationException( // "Can't delete seats from a conference that has been published at least once."); // // context.Seats.Remove(seat); // await this.retryPolicy.ExecuteAsync(async () =>await context.SaveChangesAsync()); // } private async Task PublishConferenceEvent <T>(ConferenceInfo conference) where T : ConferenceEvent, new() { await this.retryPolicy.ExecuteAsync(async() => await this.bus.Publish(new T() { SourceId = conference.Id, Owner = new Owner { Name = conference.OwnerName, Email = conference.OwnerEmail, }, Name = conference.Name, Description = conference.Description, Location = conference.Location, Slug = conference.Slug, Tagline = conference.Tagline, TwitterSearch = conference.TwitterSearch, StartDate = conference.StartDate, EndDate = conference.EndDate, })); }
/// <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); } }
public async Task CreateConference(ConferenceInfo conference) { var existingSlug = await this.retryPolicy.ExecuteAsync(async() => await context.Conferences .Where(c => c.Slug == conference.Slug) .Select(c => c.Slug) .AnyAsync()); 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); await this.retryPolicy.ExecuteAsync(async() => await context.SaveChangesAsync()); await this.PublishConferenceEvent <ConferenceCreated>(conference); }