private void LoadContent() { Person person = null; EventItem eventItem = null; // get person Guid personGuid = Guid.Empty; if (Request["PersonGuid"] != null) { personGuid = Request["PersonGuid"].AsGuid(); person = new PersonService(_rockContext).Get(personGuid); } if (person == null) { lErrors.Text = "<div class='alert alert-warning'>Invalid person guid was passed.</div>"; return; } // get calendar item id if (Request["EventItemId"] != null) { int calendarItemId = 0; int.TryParse(Request["EventItemId"], out calendarItemId); eventItem = new EventItemService(_rockContext).Get(calendarItemId); } if (eventItem == null) { lErrors.Text = "<div class='alert alert-warning'>Invalid calendar item id.</div>"; return; } lEventIntro.Text = string.Format("<h4>Select An Upcoming {0}</h4><p>", eventItem.Name); lBlockTitle.Text = string.Format("{0} Registration", eventItem.Name); var families = person.GetFamilies(); var familyMembers = person.GetFamilyMembers().ToList(); // sort family members familyMembers = familyMembers.OrderBy(f => f.GroupRole.Order) .OrderBy(f => f.Person.Gender).ToList(); if (_campusId == 0) { _campusId = families.FirstOrDefault().CampusId ?? 1; cpCampus.SelectedCampusId = _campusId; } // enter reminder email if (!string.IsNullOrWhiteSpace(person.Email)) { ebEmailReminder.Text = person.Email; } else { // find email from one of the family members ebEmailReminder.Text = familyMembers.Where(f => f.Person.Email != "").Select(f => f.Person.Email).FirstOrDefault(); } // add family registrants if (GetAttributeValue("IncludeFamilyMembers").AsBoolean()) { cblRegistrants.DataSource = familyMembers.Select(f => f.Person); cblRegistrants.DataValueField = "PrimaryAliasId"; cblRegistrants.DataTextField = "FullName"; cblRegistrants.DataBind(); } cblRegistrants.Items.Insert(0, new ListItem(person.FullName, person.PrimaryAliasId.ToString())); cblRegistrants.SelectedIndex = 0; if (cblRegistrants.Items.Count == 1) { cblRegistrants.Visible = false; } // get list of upcoming events for the current campus var eventItemOccurrences = eventItem.EventItemOccurrences .Where(c => c.CampusId == _campusId || c.CampusId == null).ToList(); List <EventSummary> eventSummaries = new List <EventSummary>(); // go through campus event schedules looking for upcoming dates foreach (var eventItemOccurrence in eventItemOccurrences) { var startDate = eventItemOccurrence.GetFirstStartDateTime(); if (startDate.HasValue && startDate > RockDateTime.Now) { EventSummary eventSummary = new EventSummary(); eventSummary.StartDate = startDate.Value; eventSummary.Name = eventItemOccurrence.EventItem.Name; eventSummary.Location = eventItemOccurrence.Location; eventSummary.Id = eventItemOccurrence.Id; if (eventItemOccurrence.Campus != null) { eventSummary.Campus = eventItemOccurrence.Campus.Name; } else { eventSummary.Campus = "All"; } eventSummary.ContactEmail = eventItemOccurrence.ContactEmail; eventSummary.ContactPhone = eventItemOccurrence.ContactPhone; if (eventItemOccurrence.ContactPersonAlias != null) { eventSummary.ContactName = eventItemOccurrence.ContactPersonAlias.Person.FullName; } else { eventSummary.ContactName = string.Empty; } eventSummary.Note = eventItemOccurrence.Note; eventSummaries.Add(eventSummary); } } int maxDisplayItems = GetAttributeValue("MaxDisplayEvents").AsInteger(); eventSummaries = eventSummaries.OrderBy(e => e.StartDate).Take(maxDisplayItems).ToList(); rptEvents.DataSource = eventSummaries; rptEvents.DataBind(); if (eventSummaries.Count > 0) { lbRegister.Enabled = true; lEventIntro.Visible = true; cblRegistrants.Visible = true; lbRegister.Visible = true; lMessages.Text = string.Empty; hfSelectedEventId.Value = eventSummaries.FirstOrDefault().Id.ToString(); } else { lbRegister.Visible = false; lEventIntro.Visible = false; cblRegistrants.Visible = false; var campus = CampusCache.Get(_campusId); lMessages.Text = string.Format("<div class='alert alert-info'>There are no {0} events for the {1} campus in the next {2} days.</div>", eventItem.Name, campus != null ? campus.Name : string.Empty, _daysInRange.ToString()); } }
private void LoadContent() { Person person = null; EventItem eventItem = null; // get person Guid personGuid = Guid.Empty; if ( Request["PersonGuid"] != null ) { personGuid = Request["PersonGuid"].AsGuid(); person = new PersonService( _rockContext ).Get( personGuid ); } if ( person == null ) { lErrors.Text = "<div class='alert alert-warning'>Invalid person guid was passed.</div>"; return; } // get calendar item id if ( Request["EventItemId"] != null ) { int calendarItemId = 0; int.TryParse( Request["EventItemId"], out calendarItemId ); eventItem = new EventItemService( _rockContext ).Get( calendarItemId ); } if ( eventItem == null ) { lErrors.Text = "<div class='alert alert-warning'>Invalid calendar item id.</div>"; return; } lEventIntro.Text = string.Format( "<h4>Select An Upcoming {0}</h4><p>", eventItem.Name ); lBlockTitle.Text = string.Format( "{0} Registration", eventItem.Name ); var families = person.GetFamilies(); var familyMembers = person.GetFamilyMembers().ToList(); // sort family members familyMembers = familyMembers.OrderBy( f => f.GroupRole.Order ) .OrderBy( f => f.Person.Gender ).ToList(); if ( _campusId == 0 ) { _campusId = families.FirstOrDefault().CampusId ?? 1; cpCampus.SelectedCampusId = _campusId; } // enter reminder email if (! string.IsNullOrWhiteSpace(person.Email)) { ebEmailReminder.Text = person.Email; } else { // find email from one of the family members ebEmailReminder.Text = familyMembers.Where( f => f.Person.Email != "" ).Select( f => f.Person.Email ).FirstOrDefault(); } // add family registrants if ( GetAttributeValue( "IncludeFamilyMembers" ).AsBoolean() ) { cblRegistrants.DataSource = familyMembers.Select( f => f.Person ); cblRegistrants.DataValueField = "PrimaryAliasId"; cblRegistrants.DataTextField = "FullName"; cblRegistrants.DataBind(); } cblRegistrants.Items.Insert( 0, new ListItem( person.FullName, person.PrimaryAliasId.ToString() ) ); cblRegistrants.SelectedIndex = 0; if ( cblRegistrants.Items.Count == 1 ) { cblRegistrants.Visible = false; } // get list of upcoming events for the current campus var eventItemOccurrences = eventItem.EventItemOccurrences .Where( c => c.CampusId == _campusId || c.CampusId == null).ToList(); List<EventSummary> eventSummaries = new List<EventSummary>(); // go through campus event schedules looking for upcoming dates foreach ( var eventItemOccurrence in eventItemOccurrences ) { var startDate = eventItemOccurrence.GetFirstStartDateTime(); if ( startDate.HasValue && startDate > RockDateTime.Now ) { EventSummary eventSummary = new EventSummary(); eventSummary.StartDate = startDate.Value; eventSummary.Name = eventItemOccurrence.EventItem.Name; eventSummary.Location = eventItemOccurrence.Location; eventSummary.Id = eventItemOccurrence.Id; if ( eventItemOccurrence.Campus != null ) { eventSummary.Campus = eventItemOccurrence.Campus.Name; } else { eventSummary.Campus = "All"; } eventSummary.ContactEmail = eventItemOccurrence.ContactEmail; eventSummary.ContactPhone = eventItemOccurrence.ContactPhone; if ( eventItemOccurrence.ContactPersonAlias != null ) { eventSummary.ContactName = eventItemOccurrence.ContactPersonAlias.Person.FullName; } else { eventSummary.ContactName = string.Empty; } eventSummary.Note = eventItemOccurrence.Note; eventSummaries.Add( eventSummary ); } } int maxDisplayItems = GetAttributeValue( "MaxDisplayEvents" ).AsInteger(); eventSummaries = eventSummaries.OrderBy( e => e.StartDate ).Take( maxDisplayItems ).ToList(); rptEvents.DataSource = eventSummaries; rptEvents.DataBind(); if ( eventSummaries.Count > 0 ) { lbRegister.Enabled = true; lEventIntro.Visible = true; cblRegistrants.Visible = true; lbRegister.Visible = true; lMessages.Text = string.Empty; hfSelectedEventId.Value = eventSummaries.FirstOrDefault().Id.ToString(); } else { lbRegister.Visible = false; lEventIntro.Visible = false; cblRegistrants.Visible = false; var campus = CampusCache.Read( _campusId ); lMessages.Text = string.Format( "<div class='alert alert-info'>There are no {0} events for the {1} campus in the next {2} days.</div>", eventItem.Name, campus != null ? campus.Name : string.Empty, _daysInRange.ToString() ); } }