public static ConcertListModel FromSearchHits(IEnumerable<ConcertSearchHit> hits)
        {
            var city = new CityModel();
            var view = new ConcertListModel()
            {

                ConcertsList = hits.Select(h => new ConcertModel
                {
                    ConcertId = int.Parse(h.ConcertId),
                    ConcertName = h.ConcertName,
                    ConcertDate = h.ConcertDate.LocalDateTime,
                    PerformerModel = new PerformerModel
                    {
                        PerformerId = h.PerformerId, ShortName = h.PerformerName
                    },
                    PerformerId = h.PerformerId,
                    VenueModel = new VenueModel
                    {
                        VenueId = h.VenueId, VenueName = h.VenueName, Description = h.PerformerName, VenueCityModel = new CityModel
                        {
                            CityName = h.VenueCity
                        }
                    },
                    VenueId = h.VenueId
                }).ToList(),
                VenuesList = hits.Select(h => new
                {
                    h.VenueId, h.VenueName, h.VenueCity, h.VenueState
                })
                                 .Distinct()
                                 .Select(v => new VenueModel
                                 {
                                     VenueId = v.VenueId, VenueName = v.VenueName, VenueCityModel = new CityModel
                                     {
                                         CityName = v.VenueCity, StateModel = new StateModel
                                         {
                                             StateName = v.VenueState
                                         }
                                     }
                                 })
                                 .ToList()
            };

            return view;
        }
Esempio n. 2
0
        public static ConcertListModel FromSearchHits(IEnumerable <ConcertSearchHit> hits)
        {
            var city = new CityModel();
            var view = new ConcertListModel()
            {
                ConcertsList = hits.Select(h => new ConcertModel
                {
                    ConcertId      = int.Parse(h.ConcertId),
                    ConcertName    = h.ConcertName,
                    ConcertDate    = h.ConcertDate.LocalDateTime,
                    PerformerModel = new PerformerModel
                    {
                        PerformerId = h.PerformerId, ShortName = h.PerformerName
                    },
                    PerformerId = h.PerformerId,
                    VenueModel  = new VenueModel
                    {
                        VenueId = h.VenueId, VenueName = h.VenueName, Description = h.PerformerName, VenueCityModel = new CityModel
                        {
                            CityName = h.VenueCity
                        }
                    },
                    VenueId = h.VenueId
                }).ToList(),
                VenuesList = hits.Select(h => new
                {
                    h.VenueId, h.VenueName, h.VenueCity, h.VenueState
                })
                             .Distinct()
                             .Select(v => new VenueModel
                {
                    VenueId = v.VenueId, VenueName = v.VenueName, VenueCityModel = new CityModel
                    {
                        CityName = v.VenueCity, StateModel = new StateModel
                        {
                            StateName = v.VenueState
                        }
                    }
                })
                             .ToList()
            };

            return(view);
        }
        public ConcertListModel GetConcertList(int venueId = 0, int cityId = 0)
        {
            // Fetch Concerts
            var concertsList = Context.Concerts.GetConcerts().Where(a => DateTime.Compare(a.ConcertDate, DateTime.Today) >= 0).ToList();

            // Roll forward expired concerts
            if (concertsList.Count < 2 && !DataHelper.RefreshConcerts(false))
            {
                UpdateStatus(string.Format("ERROR connecting to {0} database server.  Make sure: 1. The database server name, username and password in the web.config are correct, 2. Auditing is enabled on the Database Server, 3. Firewall rules allow access - including Azure Services, and 4. the Database server name resolves using nslookup.", WingtipTicketApp.Config.TenantDatabaseServer));
            }

            // Create ViewModel
            var eventListView = new ConcertListModel
            {
                SelectedVenue = venueId,
                SelectedCity = cityId,
                ConcertsList = concertsList,
                VenuesList = Context.Venues.GetVenues(cityId)
            };

            // Update Venues
            eventListView.ConcertsList.ForEach(c => c.VenueModel = eventListView.VenuesList.FirstOrDefault(a => a.VenueId == c.VenueId));
            eventListView.VenuesList.ForEach(v => v.ConcertQty = eventListView.ConcertsList.Count(a => a.VenueId == v.VenueId));

            // Filter by Venue
            if (venueId > 0)
            {
                eventListView.ConcertsList = concertsList.Where(c => c.VenueId == venueId).ToList();
                eventListView.VenuesList = eventListView.VenuesList.Where(v => v.VenueId == venueId).ToList();
            }

            // Filter by City
            if (cityId > 0)
            {
                eventListView.ConcertsList = concertsList.Where(c => c.VenueModel != null && c.VenueModel.VenueCityModel.CityId == cityId).ToList();
            }

            return eventListView;
        }