/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { if (CurrentPersonId.HasValue && CurrentPersonAliasId.HasValue) { var service = new FollowingEventSubscriptionService(_rockContext); var existingSubscriptions = service.Queryable() .Where(s => s.PersonAlias.PersonId == CurrentPersonId) .ToList(); foreach (RepeaterItem entityTypeItem in rptEntityType.Items) { var rptEvent = entityTypeItem.FindControl("rptEvent") as Repeater; if (rptEvent != null) { foreach (RepeaterItem eventItem in rptEvent.Items) { var hfEvent = eventItem.FindControl("hfEvent") as HiddenField; var cbEvent = eventItem.FindControl("cbEvent") as RockCheckBox; if (hfEvent != null && cbEvent != null) { int eventTypeId = hfEvent.ValueAsInt(); if (cbEvent.Checked) { if (!existingSubscriptions.Any(s => s.EventTypeId == eventTypeId)) { var subscription = new FollowingEventSubscription(); subscription.EventTypeId = eventTypeId; subscription.PersonAliasId = CurrentPersonAliasId.Value; service.Add(subscription); } } else { foreach (var subscription in existingSubscriptions .Where(s => s.EventTypeId == eventTypeId)) { service.Delete(subscription); } } } } } } _rockContext.SaveChanges(); nbSaved.Visible = true; } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { if ( CurrentPersonId.HasValue && CurrentPersonAliasId.HasValue ) { var service = new FollowingEventSubscriptionService( _rockContext ); var existingSubscriptions = service.Queryable() .Where( s => s.PersonAlias.PersonId == CurrentPersonId ) .ToList(); foreach ( RepeaterItem entityTypeItem in rptEntityType.Items ) { var rptEvent = entityTypeItem.FindControl( "rptEvent" ) as Repeater; if ( rptEvent != null ) { foreach ( RepeaterItem eventItem in rptEvent.Items ) { var hfEvent = eventItem.FindControl( "hfEvent" ) as HiddenField; var cbEvent = eventItem.FindControl( "cbEvent" ) as RockCheckBox; if ( hfEvent != null && cbEvent != null ) { int eventTypeId = hfEvent.ValueAsInt(); if ( cbEvent.Checked ) { if ( !existingSubscriptions.Any( s => s.EventTypeId == eventTypeId ) ) { var subscription = new FollowingEventSubscription(); subscription.EventTypeId = eventTypeId; subscription.PersonAliasId = CurrentPersonAliasId.Value; service.Add( subscription ); } } else { foreach ( var subscription in existingSubscriptions .Where( s => s.EventTypeId == eventTypeId ) ) { service.Delete( subscription ); } } } } } } _rockContext.SaveChanges(); nbSaved.Visible = true; } }