private void ShowEditDetails( EventItemOccurrence eventItemOccurrence ) { LinkageState = new EventItemOccurrenceGroupMap { Guid = Guid.Empty }; if ( eventItemOccurrence == null ) { eventItemOccurrence = new EventItemOccurrence(); } if ( eventItemOccurrence.Id == 0 ) { lActionTitle.Text = ActionTitle.Add( "Event Occurrence" ).FormatAsHtmlTitle(); var copyFromOccurrenceId = PageParameter( "CopyFromId" ).AsInteger(); if ( copyFromOccurrenceId > 0 ) { var oldOccurrence = new EventItemOccurrenceService( new RockContext() ).Get( copyFromOccurrenceId ); if ( oldOccurrence != null ) { // clone the workflow type eventItemOccurrence = oldOccurrence.Clone( false ); eventItemOccurrence.Schedule = oldOccurrence.Schedule; eventItemOccurrence.EventItem = oldOccurrence.EventItem; eventItemOccurrence.ContactPersonAlias = oldOccurrence.ContactPersonAlias; eventItemOccurrence.CreatedByPersonAlias = null; eventItemOccurrence.CreatedByPersonAliasId = null; eventItemOccurrence.CreatedDateTime = RockDateTime.Now; eventItemOccurrence.ModifiedByPersonAlias = null; eventItemOccurrence.ModifiedByPersonAliasId = null; eventItemOccurrence.ModifiedDateTime = RockDateTime.Now; eventItemOccurrence.Id = 0; eventItemOccurrence.Guid = Guid.NewGuid(); // Clone the linkage var linkage = oldOccurrence.Linkages.FirstOrDefault(); if ( linkage != null ) { LinkageState = linkage.Clone( false ); LinkageState.EventItemOccurrenceId = 0; LinkageState.CreatedByPersonAlias = null; LinkageState.CreatedByPersonAliasId = null; LinkageState.CreatedDateTime = RockDateTime.Now; LinkageState.ModifiedByPersonAlias = null; LinkageState.ModifiedByPersonAliasId = null; LinkageState.ModifiedDateTime = RockDateTime.Now; LinkageState.Id = 0; LinkageState.Guid = Guid.NewGuid(); LinkageState.RegistrationInstance = linkage.RegistrationInstance != null ? linkage.RegistrationInstance.Clone( false ) : new RegistrationInstance(); LinkageState.RegistrationInstance.RegistrationTemplate = linkage.RegistrationInstance != null && linkage.RegistrationInstance.RegistrationTemplate != null ? linkage.RegistrationInstance.RegistrationTemplate.Clone( false ) : new RegistrationTemplate(); LinkageState.Group = linkage.Group != null ? linkage.Group.Clone( false ) : new Group(); } } } } else { lActionTitle.Text = ActionTitle.Edit( "Event Occurrence" ).FormatAsHtmlTitle(); var registration = eventItemOccurrence.Linkages.FirstOrDefault(); if ( registration != null ) { LinkageState = registration.Clone( false ); LinkageState.RegistrationInstance = registration.RegistrationInstance != null ? registration.RegistrationInstance.Clone( false ) : new RegistrationInstance(); LinkageState.RegistrationInstance.RegistrationTemplate = registration.RegistrationInstance != null && registration.RegistrationInstance.RegistrationTemplate != null ? registration.RegistrationInstance.RegistrationTemplate.Clone( false ) : new RegistrationTemplate(); LinkageState.Group = registration.Group != null ? registration.Group.Clone( false ) : new Group(); } } SetEditMode( true ); hfEventItemOccurrenceId.Value = eventItemOccurrence.Id.ToString(); ddlCampus.SetValue( eventItemOccurrence.CampusId ?? -1 ); tbLocation.Text = eventItemOccurrence.Location; if ( eventItemOccurrence.Schedule != null ) { sbSchedule.iCalendarContent = eventItemOccurrence.Schedule.iCalendarContent; lScheduleText.Text = eventItemOccurrence.Schedule.FriendlyScheduleText; } else { sbSchedule.iCalendarContent = string.Empty; lScheduleText.Text = string.Empty; } ppContact.SetValue( eventItemOccurrence.ContactPersonAlias != null ? eventItemOccurrence.ContactPersonAlias.Person : null ); pnPhone.Text = eventItemOccurrence.ContactPhone; tbEmail.Text = eventItemOccurrence.ContactEmail; htmlOccurrenceNote.Text = eventItemOccurrence.Note; DisplayRegistration(); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="eventItemId">The eventItem identifier.</param> public void ShowDetail( int eventItemOccurrenceId ) { pnlDetails.Visible = true; EventItemOccurrence eventItemOccurrence = null; var rockContext = new RockContext(); bool canEdit = UserCanEdit; if ( !eventItemOccurrenceId.Equals( 0 ) ) { eventItemOccurrence = new EventItemOccurrenceService( rockContext ).Get( eventItemOccurrenceId ); } if ( eventItemOccurrence == null ) { eventItemOccurrence = new EventItemOccurrence { Id = 0 }; } if ( !canEdit ) { int? calendarId = PageParameter( "EventCalendarId" ).AsIntegerOrNull(); if ( calendarId.HasValue ) { var calendar = new EventCalendarService( rockContext ).Get( calendarId.Value ); if ( calendar != null ) { canEdit = calendar.IsAuthorized( Authorization.EDIT, CurrentPerson ); } } } bool readOnly = false; nbEditModeMessage.Text = string.Empty; if ( !canEdit ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( EventItemOccurrence.FriendlyTypeName ); } if ( readOnly ) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails( eventItemOccurrence ); } else { btnEdit.Visible = true; btnDelete.Visible = true; if ( !eventItemOccurrenceId.Equals( 0)) { ShowReadonlyDetails( eventItemOccurrence ); } else { ShowEditDetails( eventItemOccurrence ); } } }
private void ShowReadonlyDetails( EventItemOccurrence eventItemOccurrence ) { SetEditMode( false ); hfEventItemOccurrenceId.Value = eventItemOccurrence.Id.ToString(); lActionTitle.Text = "Event Occurrence".FormatAsHtmlTitle(); var leftDesc = new DescriptionList(); leftDesc.Add( "Campus", eventItemOccurrence.Campus != null ? eventItemOccurrence.Campus.Name : "All" ); leftDesc.Add( "Location Description", eventItemOccurrence.Location ); leftDesc.Add( "Schedule", eventItemOccurrence.Schedule != null ? eventItemOccurrence.Schedule.FriendlyScheduleText : string.Empty ); if ( eventItemOccurrence.Linkages.Any() ) { var linkage = eventItemOccurrence.Linkages.First(); if ( linkage.RegistrationInstance != null ) { var qryParams = new Dictionary<string, string>(); qryParams.Add( "RegistrationInstanceId", linkage.RegistrationInstance.Id.ToString() ); leftDesc.Add( "Registration", string.Format( "<a href='{0}'>{1}</a>", LinkedPageUrl( "RegistrationInstancePage", qryParams ), linkage.RegistrationInstance.Name ) ); } if ( linkage.Group != null ) { var qryParams = new Dictionary<string, string>(); qryParams.Add( "GroupId", linkage.Group.Id.ToString() ); leftDesc.Add( "Group", string.Format( "<a href='{0}'>{1}</a>", LinkedPageUrl( "GroupDetailPage", qryParams ), linkage.Group.Name ) ); } } lLeftDetails.Text = leftDesc.Html; var rightDesc = new DescriptionList(); rightDesc.Add( "Contact", eventItemOccurrence.ContactPersonAlias != null && eventItemOccurrence.ContactPersonAlias.Person != null ? eventItemOccurrence.ContactPersonAlias.Person.FullName : "" ); rightDesc.Add( "Phone", eventItemOccurrence.ContactPhone ); rightDesc.Add( "Email", eventItemOccurrence.ContactEmail ); lRightDetails.Text = rightDesc.Html; lOccurrenceNotes.Visible = !string.IsNullOrWhiteSpace( eventItemOccurrence.Note ); lOccurrenceNotes.Text = eventItemOccurrence.Note; }
/// <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 ) { EventItemOccurrence eventItemOccurrence = null; using ( var rockContext = new RockContext() ) { bool newItem = false; var eventItemOccurrenceService = new EventItemOccurrenceService( rockContext ); var eventItemOccurrenceGroupMapService = new EventItemOccurrenceGroupMapService( rockContext ); var registrationInstanceService = new RegistrationInstanceService( rockContext ); var scheduleService = new ScheduleService( rockContext ); int eventItemOccurrenceId = hfEventItemOccurrenceId.ValueAsInt(); if ( eventItemOccurrenceId != 0 ) { eventItemOccurrence = eventItemOccurrenceService .Queryable( "Linkages" ) .Where( i => i.Id == eventItemOccurrenceId ) .FirstOrDefault(); } if ( eventItemOccurrence == null ) { newItem = true; eventItemOccurrence = new EventItemOccurrence{ EventItemId = PageParameter("EventItemId").AsInteger() }; eventItemOccurrenceService.Add( eventItemOccurrence ); } int? newCampusId = ddlCampus.SelectedValueAsInt(); if ( eventItemOccurrence.CampusId != newCampusId ) { eventItemOccurrence.CampusId = newCampusId; if ( newCampusId.HasValue ) { var campus = new CampusService( rockContext ).Get( newCampusId.Value ); eventItemOccurrence.Campus = campus; } else { eventItemOccurrence.Campus = null; } } eventItemOccurrence.Location = tbLocation.Text; string iCalendarContent = sbSchedule.iCalendarContent; var calEvent = ScheduleICalHelper.GetCalenderEvent( iCalendarContent ); if ( calEvent != null && calEvent.DTStart != null ) { if ( eventItemOccurrence.Schedule == null ) { eventItemOccurrence.Schedule = new Schedule(); } eventItemOccurrence.Schedule.iCalendarContent = iCalendarContent; } else { if ( eventItemOccurrence.ScheduleId.HasValue ) { var oldSchedule = scheduleService.Get( eventItemOccurrence.ScheduleId.Value ); if ( oldSchedule != null ) { scheduleService.Delete( oldSchedule ); } } } if ( !eventItemOccurrence.ContactPersonAliasId.Equals( ppContact.PersonAliasId )) { PersonAlias personAlias = null; eventItemOccurrence.ContactPersonAliasId = ppContact.PersonAliasId; if ( eventItemOccurrence.ContactPersonAliasId.HasValue ) { personAlias = new PersonAliasService( rockContext ).Get( eventItemOccurrence.ContactPersonAliasId.Value ); } if ( personAlias != null ) { eventItemOccurrence.ContactPersonAlias = personAlias; } } eventItemOccurrence.ContactPhone = PhoneNumber.FormattedNumber( PhoneNumber.DefaultCountryCode(), pnPhone.Number ); eventItemOccurrence.ContactEmail = tbEmail.Text; eventItemOccurrence.Note = htmlOccurrenceNote.Text; // Remove any linkage no longer in UI Guid uiLinkageGuid = LinkageState != null ? LinkageState.Guid : Guid.Empty; foreach( var linkage in eventItemOccurrence.Linkages.Where( l => !l.Guid.Equals(uiLinkageGuid)).ToList()) { eventItemOccurrence.Linkages.Remove( linkage ); eventItemOccurrenceGroupMapService.Delete( linkage ); } // Add/Update linkage in UI if ( !uiLinkageGuid.Equals( Guid.Empty )) { var linkage = eventItemOccurrence.Linkages.Where( l => l.Guid.Equals( uiLinkageGuid)).FirstOrDefault(); if ( linkage == null ) { linkage = new EventItemOccurrenceGroupMap(); eventItemOccurrence.Linkages.Add( linkage ); } linkage.CopyPropertiesFrom( LinkageState ); // update registration instance if ( LinkageState.RegistrationInstance != null ) { if ( LinkageState.RegistrationInstance.Id != 0 ) { linkage.RegistrationInstance = registrationInstanceService.Get( LinkageState.RegistrationInstance.Id ); } if ( linkage.RegistrationInstance == null ) { var registrationInstance = new RegistrationInstance(); registrationInstanceService.Add( registrationInstance ); linkage.RegistrationInstance = registrationInstance; } linkage.RegistrationInstance.CopyPropertiesFrom( LinkageState.RegistrationInstance ); } } if ( !Page.IsValid ) { return; } if ( !eventItemOccurrence.IsValid ) { // Controls will render the error messages return; } rockContext.SaveChanges(); var qryParams = new Dictionary<string, string>(); qryParams.Add( "EventCalendarId", PageParameter( "EventCalendarId" ) ); qryParams.Add( "EventItemId", PageParameter( "EventItemId" ) ); if ( newItem ) { NavigateToParentPage( qryParams ); } else { qryParams.Add( "EventItemOccurrenceId", eventItemOccurrence.Id.ToString() ); NavigateToPage( RockPage.Guid, qryParams ); } } }
private void ShowEditDetails( EventItemOccurrence eventItemOccurrence ) { if ( eventItemOccurrence == null ) { eventItemOccurrence = new EventItemOccurrence(); } if ( eventItemOccurrence.Id == 0 ) { lActionTitle.Text = ActionTitle.Add( "Event Occurrence" ).FormatAsHtmlTitle(); } else { lActionTitle.Text = ActionTitle.Edit( "Event Occurrence" ).FormatAsHtmlTitle(); } SetEditMode( true ); hfEventItemOccurrenceId.Value = eventItemOccurrence.Id.ToString(); ddlCampus.SetValue( eventItemOccurrence.CampusId ?? -1 ); tbLocation.Text = eventItemOccurrence.Location; if ( eventItemOccurrence.Schedule != null ) { sbSchedule.iCalendarContent = eventItemOccurrence.Schedule.iCalendarContent; lScheduleText.Text = eventItemOccurrence.Schedule.FriendlyScheduleText; } else { sbSchedule.iCalendarContent = string.Empty; lScheduleText.Text = string.Empty; } ppContact.SetValue( eventItemOccurrence.ContactPersonAlias != null ? eventItemOccurrence.ContactPersonAlias.Person : null ); pnPhone.Text = eventItemOccurrence.ContactPhone; tbEmail.Text = eventItemOccurrence.ContactEmail; htmlOccurrenceNote.Text = eventItemOccurrence.Note; LinkageState = new EventItemOccurrenceGroupMap { Guid = Guid.Empty }; var registration = eventItemOccurrence.Linkages.FirstOrDefault(); if ( registration != null ) { LinkageState = registration.Clone( false ); LinkageState.RegistrationInstance = registration.RegistrationInstance != null ? registration.RegistrationInstance.Clone( false ) : new RegistrationInstance(); LinkageState.RegistrationInstance.RegistrationTemplate = registration.RegistrationInstance != null && registration.RegistrationInstance.RegistrationTemplate != null ? registration.RegistrationInstance.RegistrationTemplate.Clone( false ) : new RegistrationTemplate(); LinkageState.Group = registration.Group != null ? registration.Group.Clone( false ) : new Group(); } DisplayRegistration(); }