/// <summary> /// Renders the specified writer. /// </summary> /// <param name="badge">The badge.</param> /// <param name="writer">The writer.</param> public override void Render( PersonBadgeCache badge, System.Web.UI.HtmlTextWriter writer ) { RockContext rockContext = new RockContext(); var dataViewAttributeGuid = GetAttributeValue( badge, "DataView" ).AsGuid(); var dataViewService = new DataViewService( rockContext ); if ( dataViewAttributeGuid != Guid.Empty ) { var dataView = dataViewService.Get( dataViewAttributeGuid ); if ( dataView != null ) { var errors = new List<string>(); var qry = dataView.GetQuery( null, 30, out errors ); if ( qry != null && qry.Where( e => e.Id == Person.Id ).Any() ) { Dictionary<string, object> mergeValues = new Dictionary<string, object>(); mergeValues.Add( "Person", Person ); writer.Write( GetAttributeValue( badge, "BadgeContent" ).ResolveMergeFields( mergeValues ) ); } } } }
/// <summary> /// Handles the Click event of the btnEdit 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 btnEdit_Click( object sender, EventArgs e ) { var service = new DataViewService(); var item = service.Get( int.Parse( hfDataViewId.Value ) ); ShowEditDetails( item ); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> /// <param name="parentCategoryId">The parent category id.</param> public void ShowDetail( string itemKey, int itemKeyValue, int? parentCategoryId ) { pnlDetails.Visible = false; if ( !itemKey.Equals( "DataViewId" ) ) { return; } var dataViewService = new DataViewService(new RockContext()); DataView dataView = null; if ( !itemKeyValue.Equals( 0 ) ) { dataView = dataViewService.Get( itemKeyValue ); } else { dataView = new DataView { Id = 0, IsSystem = false, CategoryId = parentCategoryId }; } if ( dataView == null || !dataView.IsAuthorized( Authorization.VIEW, CurrentPerson ) ) { return; } pnlDetails.Visible = true; hfDataViewId.Value = dataView.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; string authorizationMessage = string.Empty; if ( !this.IsAuthorizedForAllDataViewComponents( Authorization.EDIT, dataView, out authorizationMessage ) ) { readOnly = true; nbEditModeMessage.Text = authorizationMessage; } if ( dataView.IsSystem ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( DataView.FriendlyTypeName ); } btnSecurity.Visible = dataView.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson ); btnSecurity.Title = dataView.Name; btnSecurity.EntityId = dataView.Id; if ( readOnly ) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails( dataView ); } else { btnEdit.Visible = true; string errorMessage = string.Empty; btnDelete.Visible = dataViewService.CanDelete( dataView, out errorMessage ); if ( dataView.Id > 0 ) { ShowReadonlyDetails( dataView ); } else { ShowEditDetails( dataView ); } } }
/// <summary> /// Handles the Click event of the btnCancel 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 btnCancel_Click( object sender, EventArgs e ) { if ( hfDataViewId.Value.Equals( "0" ) ) { int? parentCategoryId = PageParameter( "ParentCategoryId" ).AsIntegerOrNull(); if ( parentCategoryId.HasValue ) { // Cancelling on Add, and we know the parentCategoryId, so we are probably in treeview mode, so navigate to the current page var qryParams = new Dictionary<string, string>(); qryParams["CategoryId"] = parentCategoryId.ToString(); NavigateToPage( RockPage.Guid, qryParams ); } else { // Cancelling on Add. Return to Grid NavigateToParentPage(); } } else { // Cancelling on Edit. Return to Details DataViewService service = new DataViewService(new RockContext()); DataView item = service.Get( int.Parse( hfDataViewId.Value ) ); ShowReadonlyDetails( item ); } }
/// <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 ) { DataView dataView = null; var rockContext = new RockContext(); DataViewService service = new DataViewService( rockContext ); int dataViewId = int.Parse( hfDataViewId.Value ); int? dataViewFilterId = null; if ( dataViewId == 0 ) { dataView = new DataView(); dataView.IsSystem = false; } else { dataView = service.Get( dataViewId ); dataViewFilterId = dataView.DataViewFilterId; } dataView.Name = tbName.Text; dataView.Description = tbDescription.Text; dataView.TransformEntityTypeId = ddlTransform.SelectedValueAsInt(); dataView.EntityTypeId = ddlEntityType.SelectedValueAsInt(); dataView.CategoryId = cpCategory.SelectedValueAsInt(); dataView.DataViewFilter = GetFilterControl(); // update Guids since we are creating a new dataFilter and children and deleting the old one SetNewDataFilterGuids( dataView.DataViewFilter ); if ( !Page.IsValid ) { return; } if ( !dataView.IsValid ) { // Controls will render the error messages return; } if ( dataView.Id.Equals( 0 ) ) { service.Add( dataView ); } // Delete old report filter if ( dataViewFilterId.HasValue ) { DataViewFilterService dataViewFilterService = new DataViewFilterService( rockContext ); DataViewFilter dataViewFilter = dataViewFilterService.Get( dataViewFilterId.Value ); DeleteDataViewFilter( dataViewFilter, dataViewFilterService ); } rockContext.SaveChanges(); var qryParams = new Dictionary<string, string>(); qryParams["DataViewId"] = dataView.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Gets the expression. /// </summary> /// <param name="context">The context.</param> /// <param name="entityIdProperty">The entity identifier property.</param> /// <param name="selection">The selection.</param> /// <returns></returns> /// <exception cref="System.Exception"> /// Filter issue(s): One of the filters contains a circular reference to the Data View itself. /// or /// Filter issue(s): + errorMessages.AsDelimited( ; ) /// </exception> public override Expression GetExpression( RockContext context, MemberExpression entityIdProperty, string selection ) { var settings = new ParticipationRateSelectSettings(selection); if (!settings.IsValid()) { return this.GetDefaultSelectExpression( context, entityIdProperty ); } // Get the Person Data View that defines the set of candidates from which matching Group Members can be selected. DataView dataView = null; if ( settings.DataViewGuid.HasValue ) { var dsService = new DataViewService( context ); dataView = dsService.Get( settings.DataViewGuid.Value ); // Verify that there is not a child filter that uses this view (would result in stack-overflow error) if ( dsService.IsViewInFilter( dataView.Id, dataView.DataViewFilter ) ) { throw new Exception( "Filter issue(s): One of the filters contains a circular reference to the Data View itself." ); } } if ( dataView == null || dataView.DataViewFilter == null ) { return this.GetDefaultSelectExpression( context, entityIdProperty ); } // Evaluate the Data View that defines the candidate population. List<string> errorMessages; var personService = new PersonService( context ); var personQuery = personService.Queryable(); var paramExpression = personService.ParameterExpression; var whereExpression = dataView.GetExpression( personService, paramExpression, out errorMessages ); if ( errorMessages.Any() ) { throw new Exception( "Filter issue(s): " + errorMessages.AsDelimited( "; " ) ); } personQuery = personQuery.Where( paramExpression, whereExpression, null ); var populationIds = personQuery.Select( x => x.Id ); // Construct the Query to return the measure of matches for each Group. IQueryable<decimal> resultQuery; switch ( settings.MeasureType ) { case MeasureTypeSpecifier.ParticipationRateOfGroup: { // Percentage of Group Members that are also in the candidate population. resultQuery = new GroupService( context ).Queryable() .Select( p => ( p.Members.Count == 0 ) ? 0 : ( (decimal)p.Members.Count( a => ( populationIds.Contains( a.PersonId ) ) ) / (decimal)p.Members.Count ) * 100 ); } break; case MeasureTypeSpecifier.ParticipationRateOfCandidates: { // Percentage of candidate population that are also Group Members. decimal populationCount = populationIds.Count(); resultQuery = new GroupService( context ).Queryable() .Select( p => ( p.Members.Count == 0 ) ? 0 : ( (decimal)p.Members.Count( a => ( populationIds.Contains( a.PersonId ) ) ) / populationCount ) * 100 ); } break; case MeasureTypeSpecifier.NumberOfParticipants: default: { // Number resultQuery = new GroupService( context ).Queryable() .Select( p => (decimal)p.Members.Count( a => populationIds.Contains( a.PersonId ) ) ); } break; } var selectExpression = SelectExpressionExtractor.Extract<Rock.Model.Group>( resultQuery, entityIdProperty, "p" ); return selectExpression; }
/// <summary> /// Handles the GridRebind event of the gReport 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 gReport_GridRebind( object sender, EventArgs e ) { var service = new DataViewService(); var item = service.Get( int.Parse( hfDataViewId.Value ) ); ShowReport( item ); }
/// <summary> /// Handles the Click event of the btnDelete 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 btnDelete_Click( object sender, EventArgs e ) { int? categoryId = null; var dataViewService = new DataViewService(); var dataView = dataViewService.Get( int.Parse( hfDataViewId.Value ) ); if ( dataView != null ) { string errorMessage; if ( !dataViewService.CanDelete( dataView, out errorMessage ) ) { ShowReadonlyDetails( dataView ); mdDeleteWarning.Show( errorMessage, ModalAlertType.Information ); } else { categoryId = dataView.CategoryId; dataViewService.Delete( dataView, CurrentPersonId ); dataViewService.Save( dataView, CurrentPersonId ); // reload page, selecting the deleted data view's parent var qryParams = new Dictionary<string, string>(); if ( categoryId != null ) { qryParams["CategoryId"] = categoryId.ToString(); } NavigateToPage( RockPage.Guid, qryParams ); } } }
/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed ) { string formattedValue = string.Empty; Guid? guid = value.AsGuidOrNull(); if ( guid.HasValue ) { var service = new DataViewService( new RockContext() ); var dataview = service.Get( guid.Value ); if ( dataview != null ) { formattedValue = dataview.Name; } } return base.FormatValue( parentControl, formattedValue, null, condensed ); }
/// <summary> /// Sets the selection. /// Implement this version of SetSelection if your DataFilterComponent works the same in all FilterModes /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="controls">The controls.</param> /// <param name="selection">The selection.</param> public override void SetSelection( Type entityType, Control[] controls, string selection ) { var ddlDataView = controls.GetByName<DataViewPicker>( _CtlDataView ); var settings = new SelectSettings( selection ); if ( !settings.IsValid ) { return; } if ( settings.DataViewGuid.HasValue ) { var dsService = new DataViewService( new RockContext() ); var dataView = dsService.Get( settings.DataViewGuid.Value ); if ( dataView != null ) { ddlDataView.SelectedValue = dataView.Id.ToString(); } } }
/// <summary> /// Called after the save operation has been executed /// </summary> /// <remarks> /// This method is only called if <see cref="M:Rock.Data.EntitySaveHook`1.PreSave" /> returns /// without error. /// </remarks> protected override void PostSave() { // Get the current person's alias ID from the current context. var currentPersonAliasId = DbContext.GetCurrentPersonAlias()?.Id; var connectionRequest = this.Entity as ConnectionRequest; // Create and send the change notification message now that the connection request has been saved. var processConnectionRequestChangeMessage = GetProcessConnectionRequestChangeMessage(Entry, connectionRequest, currentPersonAliasId); processConnectionRequestChangeMessage.SendWhen(this.DbContext.WrappedTransactionCompletedTask); var rockContext = ( RockContext )this.RockContext; if (Entity.ConnectionStatus == null) { Entity.ConnectionStatus = new ConnectionStatusService(rockContext).Get(Entity.ConnectionStatusId); } if (Entity.ConnectionStatus != null && Entity.ConnectionStatus.AutoInactivateState && Entity.ConnectionState != ConnectionState.Inactive) { Entity.ConnectionState = ConnectionState.Inactive; rockContext.SaveChanges(); } var connectionStatusAutomationsQuery = new ConnectionStatusAutomationService(rockContext).Queryable().Where(a => a.SourceStatusId == Entity.ConnectionStatusId); if (this.Entity._runAutomationsInPostSaveChanges && connectionStatusAutomationsQuery.Any()) { var connectionStatusAutomationsList = connectionStatusAutomationsQuery.AsNoTracking().OrderBy(a => a.AutomationName).ToList(); var connectionStatusAutomations = connectionStatusAutomationsList; int changedStatusCount = 0; foreach (var connectionStatusAutomation in connectionStatusAutomations) { if (this.Entity.processedConnectionStatusAutomations.Contains(connectionStatusAutomation.Id)) { // to avoid recursion, skip over automations that have already been processed in this thread. continue; } if (Entity.ConnectionStatusId == connectionStatusAutomation.DestinationStatusId) { // If already have this status, no need to figure out if it needs to be set to this status, // or to set the status. this.Entity.processedConnectionStatusAutomations.Add(connectionStatusAutomation.Id); continue; } bool isAutomationValid = true; if (connectionStatusAutomation.DataViewId.HasValue) { // Get the dataview configured for the connection request var dataViewService = new DataViewService(rockContext); var dataview = dataViewService.Get(connectionStatusAutomation.DataViewId.Value); if (dataview != null) { var dataViewQuery = new ConnectionRequestService(rockContext).GetQueryUsingDataView(dataview); isAutomationValid = dataViewQuery.Any(a => a.Id == Entity.Id); } } if (isAutomationValid && connectionStatusAutomation.GroupRequirementsFilter != GroupRequirementsFilter.Ignore) { // Group Requirement can't be meet when either placement group or placement group role id is missing if (!Entity.AssignedGroupId.HasValue || !Entity.AssignedGroupMemberRoleId.HasValue) { isAutomationValid = false; } else { var isRequirementMeet = true; var group = new GroupService(rockContext).Get(Entity.AssignedGroupId.Value); var hasGroupRequirement = new GroupRequirementService(rockContext).Queryable().Where(a => (a.GroupId.HasValue && a.GroupId == group.Id) || (a.GroupTypeId.HasValue && a.GroupTypeId == group.GroupTypeId)).Any(); if (hasGroupRequirement) { var requirementsResults = group.PersonMeetsGroupRequirements( rockContext, Entity.PersonAlias.PersonId, Entity.AssignedGroupMemberRoleId.Value); if (requirementsResults != null && requirementsResults .Where(a => a.MeetsGroupRequirement != MeetsGroupRequirement.NotApplicable) .Any(r => r.MeetsGroupRequirement != MeetsGroupRequirement.Meets && r.MeetsGroupRequirement != MeetsGroupRequirement.MeetsWithWarning) ) { isRequirementMeet = false; } } // connection request based on if group requirement is meet or not is added to list for status update isAutomationValid = (connectionStatusAutomation.GroupRequirementsFilter == GroupRequirementsFilter.DoesNotMeet && !isRequirementMeet) || (connectionStatusAutomation.GroupRequirementsFilter == GroupRequirementsFilter.MustMeet && isRequirementMeet); } } if (isAutomationValid) { if (Entity.SetConnectionStatusFromAutomationLoop(connectionStatusAutomation)) { changedStatusCount++; rockContext.SaveChanges(); } } } } var hasHistoryChanges = HistoryChangeList?.Any() == true; var hasPersonHistoryChanges = PersonHistoryChangeList?.Any() == true; if (hasHistoryChanges || hasPersonHistoryChanges) { using (var historyRockContext = new RockContext()) { if (hasHistoryChanges) { HistoryService.SaveChanges(historyRockContext, typeof(ConnectionRequest), Rock.SystemGuid.Category.HISTORY_CONNECTION_REQUEST.AsGuid(), Entity.Id, HistoryChangeList, false, Entity.ModifiedByPersonAliasId); } if (hasPersonHistoryChanges) { var personId = Entity.PersonAlias?.PersonId ?? new PersonAliasService(rockContext).GetPersonId(Entity.PersonAliasId); if (personId.HasValue) { HistoryService.SaveChanges( historyRockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_CONNECTION_REQUEST.AsGuid(), personId.Value, PersonHistoryChangeList, "Request", typeof(ConnectionRequest), Entity.Id, false, Entity.ModifiedByPersonAliasId, rockContext.SourceOfChange); } } historyRockContext.SaveChanges(false); } } base.PostSave(); }
/// <summary> /// Called after the save operation has been executed /// </summary> /// <remarks> /// This method is only called if <see cref="M:Rock.Data.EntitySaveHook`1.PreSave" /> returns /// without error. /// </remarks> protected override void PostSave() { var rockContext = ( RockContext )this.RockContext; if (Entity.ConnectionStatus == null) { Entity.ConnectionStatus = new ConnectionStatusService(rockContext).Get(Entity.ConnectionStatusId); } if (Entity.ConnectionStatus != null && Entity.ConnectionStatus.AutoInactivateState && Entity.ConnectionState != ConnectionState.Inactive) { Entity.ConnectionState = ConnectionState.Inactive; rockContext.SaveChanges(); } if (Entity.ConnectionStatus.ConnectionStatusAutomations.Any()) { foreach (var connectionStatusAutomation in Entity.ConnectionStatus.ConnectionStatusAutomations) { bool isAutomationValid = true; if (connectionStatusAutomation.DataViewId.HasValue) { // Get the dataview configured for the connection request var dataViewService = new DataViewService(rockContext); var dataview = dataViewService.Get(connectionStatusAutomation.DataViewId.Value); if (dataview != null) { var dataViewGetQueryArgs = new DataViewGetQueryArgs { DbContext = rockContext }; isAutomationValid = dataview.GetQuery(dataViewGetQueryArgs).Any(a => a.Id == Entity.Id); } } if (isAutomationValid && connectionStatusAutomation.GroupRequirementsFilter != GroupRequirementsFilter.Ignore) { // Group Requirement can't be meet when either placement group or placement group role id is missing if (!Entity.AssignedGroupId.HasValue || !Entity.AssignedGroupMemberRoleId.HasValue) { isAutomationValid = false; } else { var isRequirementMeet = true; var group = new GroupService(rockContext).Get(Entity.AssignedGroupId.Value); var hasGroupRequirement = new GroupRequirementService(rockContext).Queryable().Where(a => (a.GroupId.HasValue && a.GroupId == group.Id) || (a.GroupTypeId.HasValue && a.GroupTypeId == group.GroupTypeId)).Any(); if (hasGroupRequirement) { var requirementsResults = group.PersonMeetsGroupRequirements( rockContext, Entity.PersonAlias.PersonId, Entity.AssignedGroupMemberRoleId.Value); if (requirementsResults != null && requirementsResults .Where(a => a.MeetsGroupRequirement != MeetsGroupRequirement.NotApplicable) .Any(r => r.MeetsGroupRequirement != MeetsGroupRequirement.Meets && r.MeetsGroupRequirement != MeetsGroupRequirement.MeetsWithWarning) ) { isRequirementMeet = false; } } // connection request based on if group requirement is meet or not is added to list for status update isAutomationValid = (connectionStatusAutomation.GroupRequirementsFilter == GroupRequirementsFilter.DoesNotMeet && !isRequirementMeet) || (connectionStatusAutomation.GroupRequirementsFilter == GroupRequirementsFilter.MustMeet && isRequirementMeet); } } if (isAutomationValid) { Entity.ConnectionStatusId = connectionStatusAutomation.DestinationStatusId; // disabled pre post processing in order to prevent circular loop that may arise due to status change. rockContext.SaveChanges(true); } } } if (HistoryChangeList?.Any() == true) { HistoryService.SaveChanges(rockContext, typeof(ConnectionRequest), Rock.SystemGuid.Category.HISTORY_CONNECTION_REQUEST.AsGuid(), Entity.Id, HistoryChangeList, true, Entity.ModifiedByPersonAliasId); } if (PersonHistoryChangeList?.Any() == true) { var personAlias = Entity.PersonAlias ?? new PersonAliasService(rockContext).Get(Entity.PersonAliasId); HistoryService.SaveChanges( rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_CONNECTION_REQUEST.AsGuid(), personAlias.PersonId, PersonHistoryChangeList, "Request", typeof(ConnectionRequest), Entity.Id, true, Entity.ModifiedByPersonAliasId, rockContext.SourceOfChange); } base.PostSave(); }
public void ParseDataViewId(string dataViewId) { var id = dataViewId.AsIntegerOrNull(); if ( id != null ) { var dsService = new DataViewService( new RockContext() ); var dataView = dsService.Get( id.Value ); DataViewGuid = dataView.Guid; } else { DataViewGuid = null; } }
/// <summary> /// Sets the selection. /// </summary> /// <param name="controls">The controls.</param> /// <param name="selection">The selection.</param> public override void SetSelection( System.Web.UI.Control[] controls, string selection ) { var settings = new ParticipationRateSelectSettings( selection ); if ( !settings.IsValid() ) { return; } var ddlDataView = (DataViewPicker)controls[0]; var ddlFormat = (DropDownList)controls[1]; if ( settings.DataViewGuid.HasValue ) { var dsService = new DataViewService( new RockContext() ); var dataView = dsService.Get( settings.DataViewGuid.Value ); if ( dataView != null ) { ddlDataView.SelectedValue = dataView.Id.ToString(); } } ddlFormat.SelectedValue = settings.MeasureType.ToString(); }
/// <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 ) { DataView dataView = null; using ( new UnitOfWorkScope() ) { DataViewService service = new DataViewService(); int dataViewId = int.Parse( hfDataViewId.Value ); int? dataViewFilterId = null; if ( dataViewId == 0 ) { dataView = new DataView(); dataView.IsSystem = false; } else { dataView = service.Get( dataViewId ); dataViewFilterId = dataView.DataViewFilterId; } dataView.Name = tbName.Text; dataView.Description = tbDescription.Text; dataView.TransformEntityTypeId = ddlTransform.SelectedValueAsInt(); dataView.EntityTypeId = ddlEntityType.SelectedValueAsInt(); dataView.CategoryId = cpCategory.SelectedValueAsInt(); dataView.DataViewFilter = GetFilterControl(); if ( !Page.IsValid ) { return; } if ( !dataView.IsValid ) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction( () => { if ( dataView.Id.Equals( 0 ) ) { service.Add( dataView, CurrentPersonId ); } service.Save( dataView, CurrentPersonId ); // Delete old report filter if ( dataViewFilterId.HasValue ) { DataViewFilterService dataViewFilterService = new DataViewFilterService(); DataViewFilter dataViewFilter = dataViewFilterService.Get( dataViewFilterId.Value ); DeleteDataViewFilter( dataViewFilter, dataViewFilterService ); dataViewFilterService.Save( dataViewFilter, CurrentPersonId ); } } ); } var qryParams = new Dictionary<string, string>(); qryParams["DataViewId"] = dataView.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Handles the Click event of the btnCancel 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 btnCancel_Click( object sender, EventArgs e ) { if ( hfDataViewId.Value.Equals( "0" ) ) { // Cancelling on Add. Return to tree view with parent category selected var qryParams = new Dictionary<string, string>(); string parentCategoryId = PageParameter( "parentCategoryId" ); if ( !string.IsNullOrWhiteSpace( parentCategoryId ) ) { qryParams["CategoryId"] = parentCategoryId; } NavigateToPage( RockPage.Guid, qryParams ); } else { // Cancelling on Edit. Return to Details DataViewService service = new DataViewService(); DataView item = service.Get( int.Parse( hfDataViewId.Value ) ); ShowReadonlyDetails( item ); } }
/// <summary> /// Shows the detail. /// </summary> /// <param name="dataViewId">The data view identifier.</param> /// <param name="parentCategoryId">The parent category id.</param> public void ShowDetail( int dataViewId, int? parentCategoryId ) { pnlDetails.Visible = false; var rockContext = new RockContext(); var dataViewService = new DataViewService( rockContext ); DataView dataView = null; if ( !dataViewId.Equals( 0 ) ) { dataView = dataViewService.Get( dataViewId ); pdAuditDetails.SetEntity( dataView, ResolveRockUrl( "~" ) ); } if ( dataView == null ) { dataView = new DataView { Id = 0, IsSystem = false, CategoryId = parentCategoryId }; dataView.Name = string.Empty; // hide the panel drawer that show created and last modified dates pdAuditDetails.Visible = false; } if ( !dataView.IsAuthorized( Authorization.VIEW, CurrentPerson ) ) { return; } pnlDetails.Visible = true; hfDataViewId.Value = dataView.Id.ToString(); hlblEditDataViewId.Text = "Id: " + dataView.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; string authorizationMessage = string.Empty; if ( !dataView.IsAuthorizedForAllDataViewComponents( Authorization.EDIT, CurrentPerson, rockContext, out authorizationMessage ) ) { readOnly = true; nbEditModeMessage.Text = authorizationMessage; } if ( dataView.IsSystem ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( DataView.FriendlyTypeName ); } btnSecurity.Visible = dataView.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson ); btnSecurity.Title = dataView.Name; btnSecurity.EntityId = dataView.Id; if ( readOnly ) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails( dataView ); } else { btnEdit.Visible = true; string errorMessage = string.Empty; btnDelete.Enabled = dataViewService.CanDelete( dataView, out errorMessage ); if (!btnDelete.Enabled) { btnDelete.ToolTip = errorMessage; btnDelete.Attributes["onclick"] = null; } if ( dataView.Id > 0 ) { ShowReadonlyDetails( dataView ); } else { ShowEditDetails( dataView ); } } }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> /// <param name="parentCategoryId">The parent category id.</param> public void ShowDetail( string itemKey, int itemKeyValue, int? parentCategoryId ) { pnlDetails.Visible = false; if ( !itemKey.Equals( "DataViewId" ) ) { return; } var dataViewService = new DataViewService(); DataView dataView = null; if ( !itemKeyValue.Equals( 0 ) ) { dataView = dataViewService.Get( itemKeyValue ); } else { dataView = new DataView { Id = 0, IsSystem = false, CategoryId = parentCategoryId }; } if ( dataView == null || !dataView.IsAuthorized( "View", CurrentPerson ) ) { return; } pnlDetails.Visible = true; hfDataViewId.Value = dataView.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if ( !dataView.IsAuthorized( "Edit", CurrentPerson ) ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( DataView.FriendlyTypeName ); } if ( dataView.DataViewFilter != null && !dataView.DataViewFilter.IsAuthorized( "View", CurrentPerson ) ) { readOnly = true; nbEditModeMessage.Text = "INFO: This Data View contains a filter that you do not have access to view."; } if ( dataView.IsSystem ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( DataView.FriendlyTypeName ); } btnSecurity.Visible = dataView.IsAuthorized( "Administrate", CurrentPerson ); btnSecurity.Title = dataView.Name; btnSecurity.EntityId = dataView.Id; if ( readOnly ) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails( dataView ); } else { btnEdit.Visible = true; string errorMessage = string.Empty; btnDelete.Visible = dataViewService.CanDelete( dataView, out errorMessage ); if ( dataView.Id > 0 ) { ShowReadonlyDetails( dataView ); } else { ShowEditDetails( dataView ); } } }
/// <summary> /// Handles the Click event of the btnDelete 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 btnDelete_Click( object sender, EventArgs e ) { int? categoryId = null; var rockContext = new RockContext(); var dataViewService = new DataViewService( rockContext ); var dataView = dataViewService.Get( int.Parse( hfDataViewId.Value ) ); if ( dataView != null ) { string errorMessage; if ( !dataViewService.CanDelete( dataView, out errorMessage ) ) { ShowReadonlyDetails( dataView ); mdDeleteWarning.Show( errorMessage, ModalAlertType.Information ); } else { categoryId = dataView.CategoryId; // delete report filter try { DataViewFilterService dataViewFilterService = new DataViewFilterService( rockContext ); DeleteDataViewFilter( dataView.DataViewFilter, dataViewFilterService ); } catch { // } dataViewService.Delete( dataView ); rockContext.SaveChanges(); // reload page, selecting the deleted data view's parent var qryParams = new Dictionary<string, string>(); if ( categoryId != null ) { qryParams["CategoryId"] = categoryId.ToString(); } NavigateToPage( RockPage.Guid, qryParams ); } } }
/// <summary> /// Sets the selection. /// Implement this version of SetSelection if your DataFilterComponent works the same in all FilterModes /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="controls">The controls.</param> /// <param name="selection">The selection.</param> public override void SetSelection( Type entityType, Control[] controls, string selection ) { var ddlDataView = controls.GetByName<DataViewPicker>( _CtlDataView ); var ddlRoleType = controls.GetByName<RockDropDownList>( _CtlRoleType ); var ddlGroupMemberStatus = controls.GetByName<RockDropDownList>( _CtlGroupStatus ); var settings = new SelectSettings( selection ); if ( !settings.IsValid ) { return; } if ( settings.DataViewGuid.HasValue ) { var dsService = new DataViewService( new RockContext() ); var dataView = dsService.Get( settings.DataViewGuid.Value ); if ( dataView != null ) { ddlDataView.SelectedValue = dataView.Id.ToString(); } } ddlRoleType.SelectedValue = settings.RoleType.ToStringSafe(); ddlGroupMemberStatus.SelectedValue = settings.MemberStatus.ToStringSafe(); }
/// <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 ) { DataView dataView = null; var rockContext = new RockContext(); DataViewService service = new DataViewService( rockContext ); int dataViewId = int.Parse( hfDataViewId.Value ); int? origDataViewFilterId = null; if ( dataViewId == 0 ) { dataView = new DataView(); dataView.IsSystem = false; } else { dataView = service.Get( dataViewId ); origDataViewFilterId = dataView.DataViewFilterId; } dataView.Name = tbName.Text; dataView.Description = tbDescription.Text; dataView.TransformEntityTypeId = ddlTransform.SelectedValueAsInt(); dataView.EntityTypeId = etpEntityType.SelectedEntityTypeId; dataView.CategoryId = cpCategory.SelectedValueAsInt(); var newDataViewFilter = ReportingHelper.GetFilterFromControls( phFilters ); if ( !Page.IsValid ) { return; } if ( !dataView.IsValid ) { // Controls will render the error messages return; } var adding = dataView.Id.Equals( 0 ); if ( adding ) { service.Add( dataView ); } rockContext.WrapTransaction( () => { if ( origDataViewFilterId.HasValue ) { // delete old report filter so that we can add the new filter (but with original guids), then drop the old filter DataViewFilterService dataViewFilterService = new DataViewFilterService( rockContext ); DataViewFilter origDataViewFilter = dataViewFilterService.Get( origDataViewFilterId.Value ); dataView.DataViewFilterId = null; rockContext.SaveChanges(); DeleteDataViewFilter( origDataViewFilter, dataViewFilterService ); } dataView.DataViewFilter = newDataViewFilter; rockContext.SaveChanges(); } ); if ( adding ) { // add EDIT and ADMINISTRATE to the person who added the dataView Rock.Security.Authorization.AllowPerson( dataView, Authorization.EDIT, this.CurrentPerson, rockContext ); Rock.Security.Authorization.AllowPerson( dataView, Authorization.ADMINISTRATE, this.CurrentPerson, rockContext ); } var qryParams = new Dictionary<string, string>(); qryParams["DataViewId"] = dataView.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }