Ejemplo n.º 1
0
        /// <summary>
        /// Binds the filter.
        /// </summary>
        private void BindFilter()
        {
            drpDates.DelimitedValues = rFilter.GetUserPreference("Date Range");

            using (var rockContext = new RockContext())
            {
                if (_person != null)
                {
                    ppPerson.Visible = false;

                    if (_group == null)
                    {
                        ddlAttendanceGroup.Visible = true;
                        ddlAttendanceGroup.Items.Clear();
                        ddlAttendanceGroup.Items.Add(new ListItem());

                        // only list groups that this person has attended before
                        var groupIdsAttended = new AttendanceService(rockContext)
                                               .Queryable().AsNoTracking()
                                               .Where(a =>
                                                      a.PersonAlias != null &&
                                                      a.PersonAlias.PersonId == _person.Id)
                                               .Select(a => a.GroupId)
                                               .Distinct()
                                               .ToList();

                        foreach (var group in new GroupService(rockContext)
                                 .Queryable().AsNoTracking()
                                 .Where(g => groupIdsAttended.Contains(g.Id))
                                 .OrderBy(g => g.Name)
                                 .Select(g => new { g.Name, g.Id }).ToList())
                        {
                            ddlAttendanceGroup.Items.Add(new ListItem(group.Name, group.Id.ToString()));
                        }

                        ddlAttendanceGroup.SetValue(rFilter.GetUserPreference("Group").AsIntegerOrNull());
                    }
                    else
                    {
                        ddlAttendanceGroup.Visible = false;
                    }
                }
                else
                {
                    ppPerson.Visible = true;
                    int?personId = rFilter.GetUserPreference("Person").AsIntegerOrNull();
                    if (personId.HasValue)
                    {
                        var person = new PersonService(rockContext).Get(personId.Value);
                        ppPerson.SetValue(person);
                    }

                    ddlAttendanceGroup.Visible = false;
                }
            }

            spSchedule.SetValue(rFilter.GetUserPreference("Schedule").AsIntegerOrNull());

            ddlDidAttend.SetValue(rFilter.GetUserPreference("Attended"));
        }