/// <summary> /// Binds the template picker. /// </summary> /// <returns><c>true</c> if any templates were displayed.</returns> private bool BindTemplatePicker() { var rockContext = new RockContext(); var templateQuery = new CommunicationTemplateService(rockContext) .Queryable() .AsNoTracking() .Where(a => a.IsActive); int?categoryId = cpCommunicationTemplate.SelectedValue.AsIntegerOrNull(); if (categoryId.HasValue && categoryId > 0) { templateQuery = templateQuery.Where(a => a.CategoryId == categoryId); } templateQuery = templateQuery.OrderBy(a => a.Name); // get list of push templates that the current user is authorized to View IEnumerable <CommunicationTemplate> templateList = templateQuery.AsNoTracking() .ToList() .Where(a => a.IsAuthorized(Rock.Security.Authorization.VIEW, this.CurrentPerson)) .Where(a => a.PushMessage.IsNotNullOrWhiteSpace()) .ToList(); rptSelectTemplate.DataSource = templateList; rptSelectTemplate.DataBind(); return(templateList.Any()); }
private void BindGrid() { var communications = new CommunicationTemplateService(new RockContext()) .Queryable("MediumEntityType,CreatedByPersonAlias.Person"); Guid entityTypeGuid = Guid.Empty; if (Guid.TryParse(rFilter.GetUserPreference("Medium"), out entityTypeGuid)) { communications = communications .Where(c => c.MediumEntityType != null && c.MediumEntityType.Guid.Equals(entityTypeGuid)); } if (_canEdit) { int personId = 0; if (int.TryParse(rFilter.GetUserPreference("Created By"), out personId) && personId != 0) { communications = communications .Where(c => c.CreatedByPersonAlias != null && c.CreatedByPersonAlias.PersonId == personId); } } var sortProperty = gCommunication.SortProperty; if (sortProperty != null) { communications = communications.Sort(sortProperty); } else { communications = communications.OrderBy(c => c.Name); } var viewableCommunications = new List <CommunicationTemplate>(); if (_canEdit) { viewableCommunications = communications.ToList(); } else { foreach (var comm in communications) { if (comm.IsAuthorized(Authorization.EDIT, CurrentPerson)) { viewableCommunications.Add(comm); } } } gCommunication.DataSource = viewableCommunications; gCommunication.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var rockContext = new RockContext(); var communicationTemplateQry = new CommunicationTemplateService(rockContext).Queryable("CreatedByPersonAlias.Person"); var privateCol = gCommunicationTemplates.ColumnsOfType <RockBoundField>().FirstOrDefault(c => c.DataField == "SenderPersonAlias.Person.FullName"); if (privateCol != null) { privateCol.Visible = GetAttributeValue("EnablePersonalTemplates").AsBoolean(); } if (_canFilterCreatedBy) { var personId = rFilter.GetUserPreference("Created By").AsIntegerOrNull(); if (personId.HasValue && personId != 0) { communicationTemplateQry = communicationTemplateQry .Where(c => c.CreatedByPersonAlias != null && c.CreatedByPersonAlias.PersonId == personId.Value); } } var categoryId = rFilter.GetUserPreference("Category").AsIntegerOrNull(); if (categoryId.HasValue && categoryId > 0) { communicationTemplateQry = communicationTemplateQry.Where(a => a.CategoryId.HasValue && a.CategoryId.Value == categoryId.Value); } var activeFilter = rFilter.GetUserPreference("Active"); switch (activeFilter) { case "Active": communicationTemplateQry = communicationTemplateQry.Where(a => a.IsActive); break; case "Inactive": communicationTemplateQry = communicationTemplateQry.Where(a => !a.IsActive); break; } var sortProperty = gCommunicationTemplates.SortProperty; communicationTemplateQry = sortProperty != null?communicationTemplateQry.Sort(sortProperty) : communicationTemplateQry.OrderBy(c => c.Name); _templatesWithCommunications = new HashSet <int>(new CommunicationService(rockContext).Queryable().Where(a => a.CommunicationTemplateId.HasValue).Select(a => a.CommunicationTemplateId.Value).Distinct().ToList()); var personalView = GetAttributeValue("PersonalTemplatesView").AsBoolean(); var viewableCommunications = new List <CommunicationTemplate>(); foreach (var comm in communicationTemplateQry.ToList()) { var isViewable = comm.IsAuthorized(personalView ? Authorization.EDIT : Authorization.VIEW, CurrentPerson); if (isViewable) { viewableCommunications.Add(comm); } } var supports = rFilter.GetUserPreference("Supports"); switch (supports) { case "Email Wizard": viewableCommunications = viewableCommunications.Where(a => a.SupportsEmailWizard()).ToList(); break; case "Simple Email Template": viewableCommunications = viewableCommunications.Where(a => !a.SupportsEmailWizard()).ToList(); break; } gCommunicationTemplates.DataSource = viewableCommunications; gCommunicationTemplates.DataBind(); }
private void BindGrid() { var communications = new CommunicationTemplateService( new RockContext() ) .Queryable( "ChannelEntityType,CreatedByPersonAlias.Person" ); Guid entityTypeGuid = Guid.Empty; if ( Guid.TryParse( rFilter.GetUserPreference( "Channel" ), out entityTypeGuid ) ) { communications = communications .Where( c => c.ChannelEntityType != null && c.ChannelEntityType.Guid.Equals( entityTypeGuid ) ); } if ( _canEdit ) { int personId = 0; if ( int.TryParse( rFilter.GetUserPreference( "Created By" ), out personId ) && personId != 0 ) { communications = communications .Where( c => c.CreatedByPersonAlias != null && c.CreatedByPersonAlias.PersonId == personId ); } } var sortProperty = gCommunication.SortProperty; if ( sortProperty != null ) { communications = communications.Sort( sortProperty ); } else { communications = communications.OrderBy( c => c.Name ); } var viewableCommunications = new List<CommunicationTemplate>(); if ( _canEdit ) { viewableCommunications = communications.ToList(); } else { foreach ( var comm in communications ) { if ( comm.IsAuthorized( Authorization.EDIT, CurrentPerson ) ) { viewableCommunications.Add( comm ); } } } gCommunication.DataSource = viewableCommunications; gCommunication.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var rockContext = new RockContext(); var communicationTemplateQry = new CommunicationTemplateService(rockContext).Queryable("CreatedByPersonAlias.Person"); if (_canEdit) { int?personId = rFilter.GetUserPreference("Created By").AsIntegerOrNull(); if (personId.HasValue && personId != 0) { communicationTemplateQry = communicationTemplateQry .Where(c => c.CreatedByPersonAlias != null && c.CreatedByPersonAlias.PersonId == personId.Value); } } int?categoryId = rFilter.GetUserPreference("Category").AsIntegerOrNull(); if (categoryId.HasValue && categoryId > 0) { communicationTemplateQry = communicationTemplateQry.Where(a => a.CategoryId.HasValue && a.CategoryId.Value == categoryId.Value); } var activeFilter = rFilter.GetUserPreference("Active"); if (activeFilter == "Active") { communicationTemplateQry = communicationTemplateQry.Where(a => a.IsActive == true); } else if (activeFilter == "Inactive") { communicationTemplateQry = communicationTemplateQry.Where(a => a.IsActive == false); } var sortProperty = gCommunicationTemplates.SortProperty; if (sortProperty != null) { communicationTemplateQry = communicationTemplateQry.Sort(sortProperty); } else { communicationTemplateQry = communicationTemplateQry.OrderBy(c => c.Name); } _templatesWithCommunications = new HashSet <int>(new CommunicationService(rockContext).Queryable().Where(a => a.CommunicationTemplateId.HasValue).Select(a => a.CommunicationTemplateId.Value).Distinct().ToList()); var viewableCommunications = new List <CommunicationTemplate>(); if (_canEdit) { viewableCommunications = communicationTemplateQry.ToList(); } else { foreach (var comm in communicationTemplateQry.ToList()) { if (comm.IsAuthorized(Authorization.EDIT, CurrentPerson)) { viewableCommunications.Add(comm); } } } var supports = rFilter.GetUserPreference("Supports"); if (supports == "Email Wizard") { viewableCommunications = viewableCommunications.Where(a => a.SupportsEmailWizard()).ToList(); } else if (supports == "Simple Email Template") { viewableCommunications = viewableCommunications.Where(a => !a.SupportsEmailWizard()).ToList(); } gCommunicationTemplates.DataSource = viewableCommunications; gCommunicationTemplates.DataBind(); }