예제 #1
0
        private EventMetadataVm CreateViewModelContract(
            EventMetadataRecord eventMeta,
            int?day,
            LoadMode mode = LoadMode.Full)
        {
            if (eventMeta == null)
            {
                throw new ArgumentNullException("eventMeta");
            }

            var result = ViewModelFactory.CreateViewModel(eventMeta, mode, _storageProvider);

            result.Host =
                EntityService
                .ViewModelFactory.CreateViewModel(eventMeta.EntityRecord, mode, _storageProvider);

            if (mode == LoadMode.Full)
            {
                result.Venues = GetEventVenues(eventMeta, day);
            }

            return(result);
        }
예제 #2
0
        private IList <EntityVm> GetEventVenues(EventMetadataRecord eventMeta, int?day)
        {
            var range      = new Tuple <DateTime?, DateTime?>(eventMeta.StartTime, eventMeta.EndTime);
            var currentDay =
                day == null
                    ? null
                    : (eventMeta.IsMultiDay() && eventMeta.StartTime.HasValue
                        ? (DateTime?)eventMeta.StartTime.Value.AddDays(day.Value)
                        : null);

            var allShows =
                eventMeta.ShowRecords
                .Where(s =>
                       !s.IsDeleted &&
                       (s.IsReference || s.StartTime.IsTimeThisDay(currentDay, range)))
                .ToArray();

            var venues = allShows
                         .Select(s => s.EntityRecord)
                         .Distinct()
                         .Select(e =>
            {
                var venueDetail = eventMeta
                                  .EventEntityDetailRecords
                                  .FirstOrDefault(eedr => !eedr.IsDeleted && eedr.EntityRecord.Id == e.Id);
                var venueVm = EntityService
                              .ViewModelFactory
                              .CreateViewModel(e, venueDetail, _storageProvider);

                venueVm.Shows = allShows
                                .Where(s => s.EntityRecord.Id == e.Id && !s.IsReference)
                                .OrderBy(s => s.StartTime)
                                .Select(s => ViewModelFactory.CreateViewModel(s, _storageProvider))
                                .ToArray();

                return(venueVm);
            });

            EntityVm[] result;

            if (eventMeta.VenueOrderType == (byte)VenueOrderType.Custom)
            {
                result = venues
                         .OrderBy(v =>
                                  v.EventDetail != null &&
                                  v.EventDetail.SortOrder != null
                            ? v.EventDetail.SortOrder.Value
                            : 0)
                         .ToArray();
            }
            else if (eventMeta.VenueOrderType == (byte)VenueOrderType.Name)
            {
                result = venues
                         .OrderBy(v => v.Name, NameComparer)
                         .ToArray();
            }
            else
            {
                result = venues.ToArray();
            }

            return(result);
        }