예제 #1
0
        /// <summary>
        /// Gets the services.
        /// </summary>
        /// <returns></returns>
        private List <Schedule> GetServices(CampusCache campus = null)
        {
            var services = new List <Schedule>();

            if (!string.IsNullOrWhiteSpace(GetAttributeValue("ScheduleCategories")))
            {
                List <Guid> categoryGuids       = GetAttributeValue("ScheduleCategories").Split(',').Select(g => g.AsGuid()).ToList();
                string      campusAttributeGuid = GetAttributeValue("CampusAttribute");

                DateTime?weekend = bddlWeekend.SelectedValue.AsDateTime();
                using (var rockContext = new RockContext())
                {
                    var attributeValueQry = new AttributeValueService(rockContext).Queryable();
                    foreach (Guid categoryGuid in categoryGuids)
                    {
                        var scheduleCategory = CategoryCache.Get(categoryGuid);
                        if (scheduleCategory != null && campus != null)
                        {
                            var schedules = new ScheduleService(rockContext)
                                            .Queryable().AsNoTracking()
                                            .Where(s => s.CategoryId == scheduleCategory.Id)
                                            .Join(
                                attributeValueQry.Where(av => av.Attribute.Guid.ToString() == campusAttributeGuid &&
                                                        av.Value.Contains(campus.Guid.ToString())),
                                p => p.Id,
                                av => av.EntityId,
                                (p, av) => new { Schedule = p, Value = av.Value });
                            // Check to see if the event was applicable the week for which we are entering data
                            foreach (var schedule in schedules)
                            {
                                var occurrences = InetCalendarHelper.GetOccurrences(schedule.Schedule.iCalendarContent, weekend.Value.Date.AddDays(-6), weekend.Value.Date.AddDays(1));
                                if (occurrences.Count > 0)
                                {
                                    services.Add(schedule.Schedule);
                                }
                            }
                        }
                        else if (scheduleCategory != null)
                        {
                            foreach (var schedule in new ScheduleService(rockContext)
                                     .Queryable().AsNoTracking()
                                     .Where(s =>
                                            s.CategoryId.HasValue &&
                                            s.CategoryId.Value == scheduleCategory.Id)
                                     .OrderBy(s => s.Name))
                            {
                                services.Add(schedule);
                            }
                        }
                    }
                }
            }
            return(services.OrderBy(s => s.GetNextStartDateTime(RockDateTime.Now).HasValue ? s.GetNextStartDateTime(RockDateTime.Now).Value.Ticks : s.EffectiveEndDate.HasValue?s.EffectiveEndDate.Value.Ticks: 0).ToList());
        }
예제 #2
0
 /// <inheritdoc cref="Rock.Model.Schedule.GetICalOccurrences(DateTime, DateTime?, DateTime?)" />
 public IList <Ical.Net.DataTypes.Occurrence> GetICalOccurrences(DateTime beginDateTime, DateTime?endDateTime, DateTime?scheduleStartDateTimeOverride)
 {
     return(InetCalendarHelper.GetOccurrences(iCalendarContent, beginDateTime, endDateTime, scheduleStartDateTimeOverride));
 }