Get() public méthode

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
Résultat IQueryable
        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 );
        }
Exemple #2
0
        /// <summary>
        /// Handles the Delete event of the gReport control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gReport_Delete( object sender, RowEventArgs e )
        {
            int id = int.MinValue;
            if ( TagId.HasValue && int.TryParse( e.RowKeyValue.ToString(), out id ) )
            {
                object obj = InvokeServiceMethod( "Get", new Type[] { typeof( int ) }, new object[] { id } );
                if ( obj != null )
                {
                    Rock.Data.IEntity entity = obj as Rock.Data.IEntity;
                    if ( entity != null )
                    {
                        var rockContext = new RockContext();
                        var service = new TaggedItemService( rockContext );
                        var taggedItem = service.Get( TagId.Value, entity.Guid );
                        if ( taggedItem != null )
                        {
                            string errorMessage;
                            if ( !service.CanDelete( taggedItem, out errorMessage ) )
                            {
                                mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                                return;
                            }

                            service.Delete( taggedItem );
                            rockContext.SaveChanges();
                        }
                    }
                }
            }

            BindGrid();
        }
Exemple #3
0
        protected void Page_Load( object sender, EventArgs e )
        {
            string entityQualifierColumn = AttributeValue( "EntityQualifierColumn" );
            if ( string.IsNullOrWhiteSpace( entityQualifierColumn ) )
                entityQualifierColumn = PageParameter( "EntityQualifierColumn" );

            string entityQualifierValue = AttributeValue( "EntityQualifierValue" );
            if ( string.IsNullOrWhiteSpace( entityQualifierValue ) )
                entityQualifierValue = PageParameter( "EntityQualifierValue" );

            var sb = new StringBuilder();

            // Get the context entity
            int? contextTypeId = null;
            Rock.Data.IEntity contextEntity = null;
            foreach ( KeyValuePair<string, Rock.Data.IEntity> entry in ContextEntities )
            {
                contextTypeId = entry.Value.TypeId;
                contextEntity = entry.Value;
                // Should only be one.
                break;
            }

            if ( contextTypeId.HasValue && contextEntity != null )
            {
                var service = new TaggedItemService();
                foreach ( dynamic item in service.Get(
                    contextTypeId.Value, entityQualifierColumn, entityQualifierValue, CurrentPersonId, contextEntity.Id )
                    .Select( i => new {
                        OwnerId = i.Tag.OwnerId,
                        Name = i.Tag.Name
                    }))
                {
                    if ( sb.Length > 0 )
                        sb.Append( ',' );
                    sb.Append( item.Name );
                    if ( CurrentPersonId.HasValue && item.OwnerId == CurrentPersonId.Value )
                        sb.Append( "^personal" );
                }

                phTags.Controls.Add( new LiteralControl( string.Format(
                    "<input name=\"person-tags\" id=\"person-tags\" value=\"{0}\" />", sb.ToString() ) ) );

                string script = string.Format( @"
            $(document).ready(function () {{
            $('ul.ui-autocomplete').css('width', '300px');
            $('#person-tags').tagsInput({{
            'autocomplete_url': function( request, response ) {{
                $.ajax({{
                    url: rock.baseUrl + 'api/tags/availablenames/{0}/{1}/{2}{3}{4}',
                    dataType: 'json',
                    success: function(data, status, xhr){{
                        response($.map(data, function (item) {{
                            return {{
                                value: item.Name,
                                class: item.OwnerId == null || item.OwnerId == '' ? 'system' : 'personal'
                            }}
                        }}))
                    }},
                    error: function(xhr, status, error) {{
                        alert(status + ' [' + error + ']: ' + xhr.reponseText);
                    }}
                }});
            }},
            autoCompleteAppendTo: 'div.tag-wrap',
            'height': 'auto',
            'width': '100%',
            'interactive': true,
            'defaultText': 'add tag',
            'removeWithBackspace': false,
            'onAddTag': verifyTag,
            'onRemoveTag': RemoveTag,
            'enableDelete': true
            }});
            }});

            function verifyTag(tagName) {{
            $.ajax({{
            type: 'GET',
            url: rock.baseUrl + 'api/tags/{0}/{1}/' + tagName + '{3}{4}',
            statusCode: {{
                404: function () {{
                        var r = confirm(""A tag called '"" + tagName + ""' does not exist. Do you want to create a new personal tag?"");
                        if (r == true) {{
                            AddTag(tagName);
                        }}
                        else {{
                            // remove tag
                            $('#person-tags').removeTag(tagName);
                        }}
                    }},
                200: function (data, status, xhr) {{
                        AddTag(tagName);
                    }}
            }},
            }});
            }}

            function AddTag(tagName) {{
            $.ajax({{
            type: 'POST',
            url: rock.baseUrl + 'api/taggeditems/{0}/{1}/{2}/' + tagName + '{3}{4}',
            error: function (xhr, status, error) {{
                alert(status + ' [' + error + ']: ' + xhr.responseText);
            }}
            }});
            }}

            function RemoveTag(tagName) {{
            $.ajax({{
            type: 'DELETE',
            url: rock.baseUrl + 'api/taggeditems/{0}/{1}/{2}/' + tagName + '{3}{4}',
            error: function (xhr, status, error) {{
                alert(status + ' [' + error + ']: ' + xhr.responseText);
            }}
            }});
            }}

            ",
            contextTypeId.Value, CurrentPersonId, contextEntity.Id,
            string.IsNullOrWhiteSpace( entityQualifierColumn ) ? "" : "/" + entityQualifierColumn,
            string.IsNullOrWhiteSpace( entityQualifierValue ) ? "" : "/" + entityQualifierValue );
                this.Page.ClientScript.RegisterStartupScript( this.GetType(), "tags-" + this.CurrentBlock.Id.ToString(), script, true );
            }
        }
Exemple #4
0
        /// <summary>
        /// Saves the tag values that user entered for the entity (
        /// </summary>
        /// <param name="personAlias">The person alias.</param>
        public void SaveTagValues(PersonAlias personAlias)
        {
            int? currentPersonId = null;
            if (personAlias != null)
            {
                currentPersonId = personAlias.PersonId;
            }

            if ( EntityGuid != Guid.Empty )
            {
                var rockContext = new RockContext();
                var tagService = new TagService( rockContext );
                var taggedItemService = new TaggedItemService( rockContext );

                // Get the existing tags for this entity type
                var existingTags = tagService.Get( EntityTypeId, EntityQualifierColumn, EntityQualifierValue, currentPersonId ).ToList();

                // Get the existing tagged items for this entity
                var existingTaggedItems = taggedItemService.Get( EntityTypeId, EntityQualifierColumn, EntityQualifierValue, currentPersonId, EntityGuid );

                // Get tag values after user edit
                var currentTags = new List<Tag>();
                foreach ( var value in this.Text.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) )
                {
                    string tagName = value;
                    if ( tagName.Contains( '^' ) )
                    {
                        tagName = tagName.Split( new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries )[0];
                    }

                    // If this is a new tag, create it
                    Tag tag = existingTags.FirstOrDefault( t => t.Name.Equals( tagName, StringComparison.OrdinalIgnoreCase ) );
                    if ( tag == null && currentPersonId != null )
                    {
                        tag = new Tag();
                        tag.EntityTypeId = EntityTypeId;
                        tag.EntityTypeQualifierColumn = EntityQualifierColumn;
                        tag.EntityTypeQualifierValue = EntityQualifierValue;
                        tag.OwnerPersonAliasId = personAlias != null ? personAlias.Id : (int?)null;
                        tag.Name = tagName;
                    }

                    if ( tag != null )
                    {
                        currentTags.Add( tag );
                    }
                }

                rockContext.SaveChanges();

                // Delete any tagged items that user removed
                var names = currentTags.Select( t => t.Name ).ToList();
                foreach ( var taggedItem in existingTaggedItems)
                {
                    if ( !names.Contains( taggedItem.Tag.Name, StringComparer.OrdinalIgnoreCase ) )
                    {
                        taggedItemService.Delete( taggedItem );
                    }
                }

                rockContext.SaveChanges();

                // Add any tagged items that user added
                names = existingTaggedItems.Select( t => t.Tag.Name ).ToList();
                foreach ( var tag in currentTags)
                {
                    if ( !names.Contains( tag.Name, StringComparer.OrdinalIgnoreCase ) )
                    {
                        var taggedItem = new TaggedItem();
                        taggedItem.TagId = tag.Id;
                        taggedItem.EntityGuid = EntityGuid;
                        taggedItemService.Add( taggedItem );
                    }
                }

                rockContext.SaveChanges();
            }
        }
Exemple #5
0
        /// <summary>
        /// Updates the control with the current tags that exist for the current entity
        /// </summary>
        /// <param name="currentPersonId">The current person identifier.</param>
        public void GetTagValues(int? currentPersonId)
        {
            var sb = new StringBuilder();

            using ( var rockContext = new RockContext() )
            {
                var service = new TaggedItemService( rockContext );
                foreach ( dynamic item in service.Get(
                    EntityTypeId, EntityQualifierColumn, EntityQualifierValue, currentPersonId, EntityGuid )
                    .Select( i => new
                    {
                        OwnerId = ( i.Tag.OwnerPersonAlias != null ? i.Tag.OwnerPersonAlias.PersonId : (int?)null ),
                        Name = i.Tag.Name
                    } ) )
                {
                    if ( sb.Length > 0 )
                        sb.Append( ',' );
                    sb.Append( item.Name );
                    if ( currentPersonId.HasValue && item.OwnerId == currentPersonId.Value )
                        sb.Append( "^personal" );
                }
            }

            this.Text = sb.ToString();
        }
        public void Delete( 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();

                    if ( name.Contains( '^' ) )
                        name = name.Split( '^' )[0];

                    var tag = tagService.Get( entityTypeId, entityQualifier, entityQualifierValue, ownerId, name );
                    if ( tag == null )
                        throw new HttpResponseException( HttpStatusCode.NotFound );

                    var taggedItem = taggedItemService.Get( tag.Id, entityGuid );
                    if ( taggedItem == null )
                        throw new HttpResponseException( HttpStatusCode.NotFound );

                    taggedItemService.Delete( taggedItem, user.PersonId );
                    taggedItemService.Save( taggedItem, user.PersonId );
                }
            }
            else
                throw new HttpResponseException( HttpStatusCode.Unauthorized );
        }
Exemple #7
0
        /// <summary>
        /// Handles the Delete event of the gReport control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gReport_Delete( object sender, RowEventArgs e )
        {
            Guid guid = Guid.Empty;
            if ( TagId.HasValue && Guid.TryParse( e.RowKeyValue.ToString(), out guid ) )
            {
                var service = new TaggedItemService();
                var taggedItem = service.Get( TagId.Value, guid );
                if ( taggedItem != null )
                {
                    string errorMessage;
                    if ( !service.CanDelete( taggedItem, out errorMessage ) )
                    {
                        mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }

                    service.Delete( taggedItem, CurrentPersonId );
                    service.Save( taggedItem, CurrentPersonId );
                }
            }

            BindGrid();
        }