Rock.Model.TaggedItemService.Get C# (CSharp) Method

Get() public method

Returns a list of TaggedItems by EntityType, QualifierColumn, QualifierValue, OwnerId and EntityGuid.
public Get ( int entityTypeId, string entityQualifierColumn, string entityQualifierValue, int ownerId, System.Guid entityGuid ) : IQueryable
entityTypeId int A representing the EntityTypeID of an of the .
entityQualifierColumn string A representing the EntityQualifierColumn of the that the /// belongs to. If a qualifier column was not used, this value can be null.
entityQualifierValue string A representing the EntityQualifierValue of the that the /// belongs to. If a qualifier value was not used, this value can be null.
ownerId int A representing the PersonId of the who is the owner of the that /// the belongs to.
entityGuid System.Guid A representing the entity Guid of the
return IQueryable
        public IQueryable<TaggedItem> Get( int entityTypeId, string entityQualifierColumn, string entityQualifierValue, int? ownerId, Guid entityGuid )
        {
            return Queryable("Tag")
                .Where( t => t.Tag.EntityTypeId == entityTypeId &&
                    ( t.Tag.EntityTypeQualifierColumn == entityQualifierColumn || (t.Tag.EntityTypeQualifierColumn == null && entityQualifierColumn == null)) &&
                    ( t.Tag.EntityTypeQualifierValue == entityQualifierValue || (t.Tag.EntityTypeQualifierValue == null && entityQualifierValue == null)) &&
                    ( t.Tag.OwnerPersonAlias == null || ( ownerId.HasValue && t.Tag.OwnerPersonAlias.PersonId == ownerId ) ) &&
                    t.EntityGuid == entityGuid
                    )
                .OrderBy( t => t.Tag.Name);
        }

Same methods

TaggedItemService::Get ( int tagId, System.Guid entityGuid ) : TaggedItem

Usage Example

        public HttpResponseMessage Post( int entityTypeId, int ownerId, Guid entityGuid, string name, string entityQualifier, string entityQualifierValue )
        {
            var user = CurrentUser();
            if ( user != null )
            {
                using ( new Rock.Data.UnitOfWorkScope() )
                {
                    var tagService = new TagService();
                    var taggedItemService = new TaggedItemService();

                    var tag = tagService.Get( entityTypeId, entityQualifier, entityQualifierValue, ownerId, name );
                    if ( tag == null )
                    {
                        tag = new Tag();
                        tag.EntityTypeId = entityTypeId;
                        tag.EntityTypeQualifierColumn = entityQualifier;
                        tag.EntityTypeQualifierValue = entityQualifierValue;
                        tag.OwnerId = ownerId;
                        tag.Name = name;
                        tagService.Add( tag, user.PersonId );
                        tagService.Save( tag, user.PersonId );
                    }

                    var taggedItem = taggedItemService.Get( tag.Id, entityGuid );
                    if ( taggedItem == null )
                    {
                        taggedItem = new TaggedItem();
                        taggedItem.TagId = tag.Id;
                        taggedItem.EntityGuid = entityGuid;
                        taggedItemService.Add( taggedItem, user.PersonId );
                        taggedItemService.Save( taggedItem, user.PersonId );
                    }
                }

                return ControllerContext.Request.CreateResponse( HttpStatusCode.Created );
            }

            throw new HttpResponseException( HttpStatusCode.Unauthorized );
        }
All Usage Examples Of Rock.Model.TaggedItemService::Get
TaggedItemService