public async Task Process() { var eventBriteEvents = await _eventBriteServices.GetEvents(); var minesFromEventBrite = _context.Events.Where(x => x.Platform == EventPlatform.EventBrite).Select(x => x.EventId) .ToList(); var eventEventBriteProcesseds = eventBriteEvents.Aggregate(new List <Event>(), (list, @event) => { if (!minesFromEventBrite.Any(x => x == @event.Id)) { list.Add(new Event { Description = @event.Description.Text, Title = @event.Name.Text, Url = @event.Url, EventId = @event.Id.ToString(), Date = @event.Start.Utc.Date, ImageUrl = @event.Logo?.Original?.Url?.OriginalString, Platform = EventPlatform.EventBrite }); } return(list); }); _context.Events.AddRange(eventEventBriteProcesseds); await _context.SaveChangesAsync(); foreach (var eventBriteProcessed in eventEventBriteProcesseds) { await _syncServices.SyncEvent(eventBriteProcessed.Id); } }
public async Task Process() { var eventsToAdd = await _meetupServices.GetAllEvents(); var mines = _context.Events.Where(x => x.Platform == EventPlatform.Meetup).ToList(); var eventMeetupProcesseds = new List <Event>(); foreach (var eventToAdd in eventsToAdd) { var eventToCheck = mines.FirstOrDefault(x => x.EventId == eventToAdd.Id.ToString()); if (eventToCheck == null) { eventMeetupProcesseds.Add(new Event { Description = eventToAdd.Description, Title = eventToAdd.Name, Url = eventToAdd.Link.AbsoluteUri, EventId = eventToAdd.Id.ToString(), Date = eventToAdd.LocalDate.Date, ImageUrl = eventToAdd?.FeaturedPhoto?.HighresLink?.AbsoluteUri, Platform = EventPlatform.Meetup }); _logger.LogInformation($"Created new event from Meetup : {eventToAdd.Id.ToString()}"); } else if (!eventToCheck.Done) { eventMeetupProcesseds.Add(eventToCheck); } } if (eventMeetupProcesseds.Any()) { _context.Events.AddRange(eventMeetupProcesseds.Where(x => x.Id == 0)); } await _context.SaveChangesAsync(); foreach (var eventMeetupProcessed in eventMeetupProcesseds) { await _syncServices.SyncEvent(eventMeetupProcessed.Id); } }