Example #1
0
        public async Task <CategoryInfo> GetEventDetails(string searchTerms)
        {
            //Validating input
            if (searchTerms.IsNullOrWhiteSpace())
            {
                return(null);;
            }

            var api = _viagogoApiProvider.GetViagogoApiClient();

            //Searching on search terms
            var searchResult = await api.Search.GetAllAsync(searchTerms);

            if (searchResult.Count == 0)
            {
                return(null);
            }

            //Extracting artist node from search terms
            var artistSearchResult = searchResult
                                     .FirstOrDefault(sr => sr.Type == Category && sr.TypeDescription == Artist);

            if (artistSearchResult == null || artistSearchResult.CategoryLink == null)
            {
                return(null);
            }

            //Fetching artist details
            var artistDetails = await api.Hypermedia
                                .GetAsync <Category>(artistSearchResult.CategoryLink);

            if (artistDetails == null || artistDetails.EventsLink == null)
            {
                return(null);
            }

            //Fetching events for that artist
            var events = await api.Hypermedia
                         .GetAllPagesAsync <Event>(artistDetails.EventsLink);

            var eventDetails = new CategoryInfo()
            {
                Title       = artistDetails.Name,
                Description = artistDetails.Description,
                MainImage   = new Image()
                {
                    Href  = artistDetails.ImageLink.HRef,
                    Title = artistDetails.ImageLink.Title
                },
                MaxEventDate   = artistDetails.MaxEventDate,
                MinTicketPrice = artistDetails.MinTicketPrice,
                EventDetails   = events.Select(e => new EventInfo()
                {
                    MinTicketPrice              = e.MinTicketPrice,
                    Notes                       = e.Notes,
                    Venue                       = e.Venue,
                    IsCountryMinPrice           = false,
                    NumberOfEventsInSameCountry = 1,
                    Date        = e.StartDate,
                    TicketsLink = e.ListingsLink?.HRef ?? "",
                    Id          = e.Id
                }).ToList()
            };

            EventsHelper.AugmentEventInfos(eventDetails.EventDetails);

            return(eventDetails);
        }