Пример #1
0
        /// <summary>
        /// Schedule content view model for mobile.
        /// </summary>
        /// <returns>The content view model to be used when displaying on mobile.</returns>
        private ContentBag GetScheduleContent()
        {
            using (var rockContext = new RockContext())
            {
                var currentDateTime = RockDateTime.Now.Date;

                // Query the confirmed attendances.
                var confirmedScheduleList = new AttendanceService(rockContext)
                                            .GetConfirmedScheduled()
                                            .Where(a => a.PersonAlias.PersonId == this.CurrentPersonId)
                                            .Where(a => a.Occurrence.OccurrenceDate >= currentDateTime)
                                            .Select(a => new GroupScheduleRowInfo
                {
                    Guid = a.Guid,
                    Id   = a.Id,
                    OccurrenceStartDate = a.Occurrence.OccurrenceDate,
                    Group             = a.Occurrence.Group,
                    Schedule          = a.Occurrence.Schedule,
                    Location          = a.Occurrence.Location,
                    GroupScheduleType = GroupScheduleType.Upcoming
                }).ToList();

                // Query the pending attendances.
                var pendingScheduleList = new AttendanceService(rockContext)
                                          .GetPendingScheduledConfirmations()
                                          .Where(a => a.PersonAlias.PersonId == this.CurrentPersonId)
                                          .Where(a => a.Occurrence.OccurrenceDate >= currentDateTime)
                                          .Select(a => new GroupScheduleRowInfo
                {
                    Guid = a.Guid,
                    Id   = a.Id,
                    OccurrenceStartDate = a.Occurrence.OccurrenceDate,
                    Group             = a.Occurrence.Group,
                    Schedule          = a.Occurrence.Schedule,
                    Location          = a.Occurrence.Location,
                    GroupScheduleType = GroupScheduleType.Pending
                }).ToList();

                // Query the declined attendances.
                var declinedScheduleList = new AttendanceService(rockContext)
                                           .GetDeclinedScheduleConfirmations()
                                           .Where(a => a.PersonAlias.PersonId == this.CurrentPersonId)
                                           .Where(a => a.Occurrence.OccurrenceDate >= currentDateTime)
                                           .Select(a => new GroupScheduleRowInfo
                {
                    Guid = a.Guid,
                    Id   = a.Id,
                    OccurrenceStartDate = a.Occurrence.OccurrenceDate,
                    Group             = a.Occurrence.Group,
                    Schedule          = a.Occurrence.Schedule,
                    Location          = a.Occurrence.Location,
                    GroupScheduleType = GroupScheduleType.Unavailable
                }).ToList();

                // Now we are going to take the two lists and merge them. Since we already know the size of the list, we can use that.
                // We can do this to help increase performance.
                // Source: https://stackoverflow.com/a/4488073/15341894.
                var scheduleList = new List <GroupScheduleRowInfo>(confirmedScheduleList.Count() + pendingScheduleList.Count());
                scheduleList.AddRange(confirmedScheduleList);
                scheduleList.AddRange(pendingScheduleList);
                scheduleList.AddRange(declinedScheduleList);
                scheduleList = scheduleList.OrderBy(x => x.OccurrenceStartDate).ToList();

                // The dictionary of merge fields.
                var mergeFields = RequestContext.GetCommonMergeFields();

                // Add in the pending and confirmed attendances.
                mergeFields.AddOrReplace("ScheduleList", scheduleList);

                // Pass those in as content.
                var content = TypeTemplate.ResolveMergeFields(mergeFields);

                return(new ContentBag
                {
                    Content = content,
                });
            }
        }
Пример #2
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection)
        {
            string[] options = selection.Split('|');
            if (options.Length < 4)
            {
                return(null);
            }

            Guid groupTypeGuid = options[0].AsGuid();

            var        campusGuidList = options[0].Split(',').AsGuidList();
            List <int> campusIds      = new List <int>();

            foreach (var campusGuid in campusGuidList)
            {
                var campus = CampusCache.Get(campusGuid);
                if (campus != null)
                {
                    campusIds.Add(campus.Id);
                }
            }

            if (!campusIds.Any())
            {
                return(null);
            }

            ComparisonType comparisonType = options[1].ConvertToEnum <ComparisonType>(ComparisonType.GreaterThanOrEqualTo);
            int?           attended       = options[2].AsIntegerOrNull();
            string         slidingDelimitedValues;

            if (options[3].AsIntegerOrNull().HasValue)
            {
                //// selection was from when it just simply a LastXWeeks instead of Sliding Date Range
                // Last X Weeks was treated as "LastXWeeks * 7" days, so we have to convert it to a SlidingDateRange of Days to keep consistent behavior
                int lastXWeeks = options[3].AsIntegerOrNull() ?? 1;
                var fakeSlidingDateRangePicker = new SlidingDateRangePicker();
                fakeSlidingDateRangePicker.SlidingDateRangeMode = SlidingDateRangePicker.SlidingDateRangeType.Last;
                fakeSlidingDateRangePicker.TimeUnit             = SlidingDateRangePicker.TimeUnitType.Day;
                fakeSlidingDateRangePicker.NumberOfTimeUnits    = lastXWeeks * 7;
                slidingDelimitedValues = fakeSlidingDateRangePicker.DelimitedValues;
            }
            else
            {
                slidingDelimitedValues = options[3].Replace(',', '|');
            }

            var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(slidingDelimitedValues);

            var rockContext   = serviceInstance.Context as RockContext;
            var attendanceQry = new AttendanceService(rockContext).Queryable().Where(a => a.DidAttend.HasValue && a.DidAttend.Value);

            attendanceQry = attendanceQry.Where(a => a.CampusId.HasValue && campusIds.Contains((int)a.CampusId));

            if (dateRange.Start.HasValue)
            {
                var startDate = dateRange.Start.Value;
                attendanceQry = attendanceQry.Where(a => a.Occurrence.OccurrenceDate >= startDate);
            }

            if (dateRange.End.HasValue)
            {
                var endDate = dateRange.End.Value;
                attendanceQry = attendanceQry.Where(a => a.Occurrence.OccurrenceDate < endDate);
            }

            var qry = new PersonService(rockContext).Queryable()
                      .Where(p => attendanceQry.Count(xx => xx.PersonAlias.PersonId == p.Id) == attended);

            var compareEqualExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p") as BinaryExpression;
            var result = FilterExpressionExtractor.AlterComparisonType(comparisonType, compareEqualExpression, null);

            return(result);
        }