public static XtracurEventsIndexMonthViewModel Build(XtracurDivision xtracurDivision, DateTime?month,
                                                             int?showImmediateEventId, int?showImmediateRecurrenceIndex)
        {
            var language = CultureHelper.CurrentLanguage;
            var firstDayOfCurrentMonth     = DateTimeHelper.GetFirstDayOfCurrentMonth();
            var firstDayOfChosenMonth      = DateTimeHelper.GetFirstDayOfMonth(month);
            var firstDayOfTheNextMonth     = DateTimeHelper.GetFirstDayOfTheNextMonth(firstDayOfChosenMonth);
            var firstDayOfThePreviousMonth = DateTimeHelper.GetFirstDayOfThePreviousMonth(firstDayOfChosenMonth);
            var eventGroupings             = EventsViewModelHelper.GetXtracurEventGroupings(xtracurDivision,
                                                                                            firstDayOfChosenMonth, firstDayOfTheNextMonth, showImmediateEventId, showImmediateRecurrenceIndex);

            return(new XtracurEventsIndexMonthViewModel
            {
                Alias = xtracurDivision.Alias,
                Title = xtracurDivision.GetNameByLanguage(language),
                IsCurrentMonthReferenceAvailable = firstDayOfCurrentMonth != firstDayOfChosenMonth,
                ChosenMonthDisplayText = GetMonthDisplayText(firstDayOfChosenMonth),
                PreviousMonthDisplayText = GetPreviousMonthDisplayText(firstDayOfThePreviousMonth),
                PreviousMonthDate = DateTimeHelper.GetDateStringForWeb(firstDayOfThePreviousMonth),
                NextMonthDisplayText = GetNextMonthDisplayText(firstDayOfTheNextMonth),
                NextMonthDate = DateTimeHelper.GetDateStringForWeb(firstDayOfTheNextMonth),
                EventGroupings = eventGroupings,
                ShowGroupingCaptions = eventGroupings.Count() > 1,
                HasEventsToShow = eventGroupings.Any(eg => eg.Events.Any(e => !e.IsShowImmediateHidden)),
                Breadcrumb = new Breadcrumb()
                {
                    BreadcrumbHelper.GetBreadcrumbRootItem(false),
                    BreadcrumbHelper.GetBreadcrumbXtracurEventsItem(xtracurDivision, true)
                }
            });
        }
        public new static XtracurEventsIndexWeekViewModel Build(XtracurDivision xtracurDivision, DateTime?fromDate,
                                                                int?showImmediateEventId, int?showImmediateRecurrenceIndex)
        {
            var language             = CultureHelper.CurrentLanguage;
            var weekFromDate         = DateTimeHelper.GetWeekStart(fromDate);
            var weekToDate           = weekFromDate.AddDays(7);
            var previousWeekFromDate = weekFromDate.AddDays(-7);
            var nextWeekFromDate     = weekFromDate.AddDays(7);
            var currentWeekFromDate  = DateTimeHelper.GetWeekStart(DateTime.Today);
            var events   = EventsViewModelHelper.GetXtracurEvents(xtracurDivision, weekFromDate, weekToDate, showImmediateEventId, showImmediateRecurrenceIndex).ToList();
            var weekDays = events.Where(e => e.Start >= weekFromDate)
                           .GroupBy(vm => vm.Start.Date)
                           .OrderBy(g => g.Key)
                           .Select(g => EventsDayViewModel.Build(g.Key, g.AsEnumerable()));
            var earlierEvents = events.Where(e => e.Start < weekFromDate);

            return(new XtracurEventsIndexWeekViewModel
            {
                Alias = xtracurDivision.Alias,
                Title = xtracurDivision.GetNameByLanguage(language),
                EarlierEvents = earlierEvents,
                Days = weekDays,
                WeekDisplayText = DateTimeHelper.GetWeekDisplayText(language, weekFromDate, weekToDate),
                PreviousWeekMonday = DateTimeHelper.GetDateStringForWeb(previousWeekFromDate),
                WeekMonday = DateTimeHelper.GetDateStringForWeb(weekFromDate),
                NextWeekMonday = DateTimeHelper.GetDateStringForWeb(nextWeekFromDate),
                IsCurrentWeekReferenceAvailable = (currentWeekFromDate != weekFromDate),
                HasEventsToShow = events.Any(e => !e.IsShowImmediateHidden),
                Breadcrumb = new Breadcrumb()
                {
                    BreadcrumbHelper.GetBreadcrumbRootItem(false),
                    BreadcrumbHelper.GetBreadcrumbXtracurEventsItem(xtracurDivision, true)
                }
            });
        }
Ejemplo n.º 3
0
        public static XtracurEventsSearchViewModel Build(XtracurDivision xtracurDivision, string query, int?offset, bool?showPast)
        {
            LanguageCode language     = CultureHelper.CurrentLanguage;
            bool         isEmptyQuery = String.IsNullOrWhiteSpace(query);
            int          totalCount;
            var          today = DateTime.Today;
            IEnumerable <XtracurEventItemViewModel> events = Enumerable.Empty <XtracurEventItemViewModel>();

            if (!showPast.HasValue && !offset.HasValue)
            {
                var upcomingEvents = GetEvents(xtracurDivision, query, 0, today, DateTimeHelper.MaxValue, out totalCount);
                if (upcomingEvents.Any())
                {
                    events   = upcomingEvents;
                    showPast = false;
                }
                else
                {
                    var pastEvents = GetEvents(xtracurDivision, query, 0, DateTimeHelper.MinValue, today.AddDays(1), out totalCount);
                    if (pastEvents.Any())
                    {
                        events   = pastEvents;
                        showPast = true;
                    }
                }
            }
            else
            {
                var fromDate = showPast.Value ? DateTimeHelper.MinValue : today;
                var toDate   = showPast.Value ? today.AddDays(1) : DateTimeHelper.MaxValue;
                events = GetEvents(xtracurDivision, query, offset ?? 0, fromDate, toDate, out totalCount);
            }
            IEnumerable <XtracurEventsSearchPagerItemViewModel> pagerItems = GeneratePagerItems(offset ?? 0, (totalCount - 1) / ItemsOnPageCount + 1);

            return(new XtracurEventsSearchViewModel
            {
                Alias = xtracurDivision.Alias,
                Title = xtracurDivision.GetNameByLanguage(language),
                Events = events,
                PagerItems = pagerItems,
                ShowPager = pagerItems.Any(pi => pi.IsEnabled && !pi.IsActive),
                ShowPast = showPast ?? false,
                ShowUpcoming = showPast.HasValue ? !(showPast ?? false) : false,
                IsEmptyQuery = isEmptyQuery,
                Offset = offset ?? 0,
                QueryDisplayText = query,
                Breadcrumb = new Breadcrumb()
                {
                    BreadcrumbHelper.GetBreadcrumbRootItem(false),
                    BreadcrumbHelper.GetBreadcrumbXtracurEventsItem(xtracurDivision, false),
                    BreadcrumbHelper.GetBreadcrumbXtracurSearchItem(true)
                }
            });
        }