Rock.Model.TagService.Get C# (CSharp) Метод

Get() публичный Метод

Returns a queryable collection of Tags by EntityType, Qualifier Column, Qualifier Value and Owner.
public Get ( int entityTypeId, string entityQualifierColumn, string entityQualifierValue, int ownerId ) : IQueryable
entityTypeId int A representing the EntityTypeID of the of the entities that are eligible for the .
entityQualifierColumn string A that represents the EntityQualifierColumn of the . This value can be null.
entityQualifierValue string A that represents the EntityQualifierValue of the . This value can be null.
ownerId int A representing the owner's PersonId. If the is public this value can be null.
Результат IQueryable
        public IQueryable<Tag> Get( int entityTypeId, string entityQualifierColumn, string entityQualifierValue, int? ownerId )
        {
            return Queryable()
                .Where( t => t.EntityTypeId == entityTypeId &&
                    ( t.EntityTypeQualifierColumn == null || t.EntityTypeQualifierColumn == "" || t.EntityTypeQualifierColumn == entityQualifierColumn ) &&
                    ( t.EntityTypeQualifierValue == null || t.EntityTypeQualifierValue == "" || t.EntityTypeQualifierValue == entityQualifierValue ) &&
                    ( t.OwnerPersonAlias == null || (ownerId.HasValue && t.OwnerPersonAlias.PersonId == ownerId) )
                    )
                .OrderBy( t => t.Name );
        }

Same methods

TagService::Get ( int entityTypeId, string entityQualifierColumn, string entityQualifierValue, int ownerId, string name ) : Tag

Usage Example

Пример #1
0
        /// <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)
        {
            var rockContext = new RockContext();
            var tagService  = new Rock.Model.TagService(rockContext);
            Tag tag         = null;

            int tagId = int.Parse(hfId.Value);

            if (tagId != 0)
            {
                tag = tagService.Get(tagId);
            }

            if (tag == null)
            {
                tag          = new Tag();
                tag.IsSystem = false;
                tagService.Add(tag);
            }

            string name         = tbName.Text;
            int?   ownerId      = ppOwner.PersonId;
            int    entityTypeId = ddlEntityType.SelectedValueAsId().Value;
            string qualifierCol = tbEntityTypeQualifierColumn.Text;
            string qualifierVal = tbEntityTypeQualifierValue.Text;

            // Verify tag with same name does not already exist
            if (tagService.Queryable()
                .Where(t =>
                       t.Id != tagId &&
                       t.Name == name &&
                       t.OwnerId.Equals(ownerId) &&
                       t.EntityTypeId == entityTypeId &&
                       t.EntityTypeQualifierColumn == qualifierCol &&
                       t.EntityTypeQualifierValue == qualifierVal)
                .Any())
            {
                nbEditError.Heading = "Tag Already Exists";
                nbEditError.Text    = string.Format("A '{0}' tag already exists for the selected scope, owner, and entity type.", name);
                nbEditError.Visible = true;
            }
            else
            {
                tag.Name         = name;
                tag.Description  = tbDescription.Text;
                tag.OwnerId      = ownerId;
                tag.EntityTypeId = entityTypeId;
                tag.EntityTypeQualifierColumn = qualifierCol;
                tag.EntityTypeQualifierValue  = qualifierVal;
                rockContext.SaveChanges();

                var qryParams = new Dictionary <string, string>();
                qryParams["tagId"] = tag.Id.ToString();

                NavigateToPage(RockPage.Guid, qryParams);
            }
        }
All Usage Examples Of Rock.Model.TagService::Get
TagService