public async Task TakeEventsAndPostAsList(Token token) { CustomLogger.Log("infoLog", "Rozpoczęto zadanie z Wrocławia."); var dateFrom = DateHelper.GetEventDateFromString(DateFrom); var dateTo = DateHelper.GetEventDateFromString(DateTo); var cityId = await EventerApiService.GetCityId(token, "Wrocław"); var allEventerEvents = await EventerApiService.GetEvents(token, cityId); var wroclawEventsToPost = new List <EventPostItem>(); var wrocEvents = await GetEventsFromWroclawGoApi(); var wroclawEventsToAdd = wrocEvents.Where(w => !allEventerEvents.Any(e => e.EventName.Equals(w.Offer.Title) && e.EventLocalization.Equals(w.PlaceName) && e.EventDate == DateHelper.GetEventDateFromString(w.StartDate)) && (DateHelper.GetEventDateFromString(w.StartDate) >= dateFrom && DateHelper.GetEventDateFromString(w.StartDate) <= dateTo)).ToList(); foreach (var @event in wroclawEventsToAdd) { var eventName = @event.Offer.Title; var eventDate = DateHelper.GetEventDateFromString(@event.StartDate); var eventLocalization = @event.PlaceName; var eventImage = @event.Offer.MainImage?.Standard; var eventUrl = @event.Offer.PageLink; var eventDescription = @event.Offer.LongDescription; var eventCategories = @event.Offer.Categories.Select(c => c.Name).ToList(); var newEvent = new EventPostItem { EventName = eventName, EventDate = eventDate, EventLocalization = eventLocalization, EventImage = eventImage, EventUrl = eventUrl, EventDescription = eventDescription, Categories = eventCategories, CityId = cityId }; wroclawEventsToPost.Add(newEvent); } var eventItemPostList = new EventItemPostList { Events = wroclawEventsToPost }; var postEventsResult = await EventerApiService.PostEventAsList(token, eventItemPostList, "wrocEventLog"); CustomLogger.Log("infoLog", postEventsResult ? $"Zakończono zadanie z Wrocławia. Dodano {wroclawEventsToPost.Count} eventów." : "Zakończono zadanie z Wrocławia. Nie dodano eventów."); }
public async Task TakeEventsAndPostAsList(Token token) { CustomLogger.Log("infoLog", "Rozpoczęto zadanie z Poznania."); var dateFrom = DateHelper.GetEventDateFromString(DateFrom); var dateTo = DateHelper.GetEventDateFromString(DateTo); var cityId = await EventerApiService.GetCityId(token, "Poznań"); var allEventerEvents = await EventerApiService.GetEvents(token, cityId); var poznanEventsToAdd = new List <PoznanApiEvent>(); var poznanEventsToPost = new List <EventPostItem>(); var poznanEvents = await GetEventsFromPoznanApi(); foreach (var @event in poznanEvents.Event) { var latestEventVersion = @event.EventVersion.Last(); var latestVersion = latestEventVersion.Version.Last(); var latestAddress = @event.EventAddress.Last(); var poznanEventDate = DateHelper.GetEventDateFromString(@event.EventDate); if (!(poznanEventDate >= dateFrom && poznanEventDate <= dateTo)) { continue; } if (allEventerEvents.Any(x => x.EventName.Equals(latestVersion.EventName) && x.EventDate == poznanEventDate && x.EventLocalization.Equals(latestAddress.EventLocalization))) { continue; } if (poznanEventsToAdd.Contains(@event)) { continue; } poznanEventsToAdd.Add(@event); } foreach (var @event in poznanEventsToAdd) { var latestEventVersion = @event.EventVersion.Last(); var latestVersion = latestEventVersion.Version.Last(); var latestAddress = @event.EventAddress.Last(); var eventName = latestVersion.EventName; var eventDate = DateHelper.GetEventDateFromString(@event.EventDate); var eventLocalization = latestAddress.EventLocalization; var eventUrl = @event.EventUrl; var eventDescription = latestVersion.EventDescription; var categories = new List <string> { @event.EventCategory }; var newEvent = new EventPostItem { EventName = eventName, EventDate = eventDate, EventLocalization = eventLocalization, EventUrl = eventUrl, EventDescription = eventDescription, Categories = categories, CityId = cityId }; poznanEventsToPost.Add(newEvent); } var eventItemPostList = new EventItemPostList { Events = poznanEventsToPost }; var postEventsResult = await EventerApiService.PostEventAsList(token, eventItemPostList, "poznEventLog"); CustomLogger.Log("infoLog", postEventsResult ? $"Zakończono zadanie z Poznania. Dodano {poznanEventsToPost.Count} eventów." : "Zakończono zadanie z Poznania. Nie dodano eventów."); }