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
Пример #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);
            }
        }
Пример #2
0
        public Tag Get( int entityTypeId, int ownerId, string name, string entityQualifier, string entityQualifierValue )
        {
            var service = new TagService();
            var tag = service.Get( entityTypeId, entityQualifier, entityQualifierValue, ownerId ).FirstOrDefault(t => t.Name == name);

            if ( tag != null )
                return tag;
            else
                throw new HttpResponseException( HttpStatusCode.NotFound );
        }
Пример #3
0
        /// <summary>
        /// Handles the Delete event of the rGrid 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 rGrid_Delete(object sender, RowEventArgs e)
        {
            var tagService = new Rock.Model.TagService();
            var tag        = tagService.Get((int)rGrid.DataKeys[e.RowIndex]["id"]);

            if (tag != null)
            {
                string errorMessage;
                if (!tagService.CanDelete(tag, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                tagService.Delete(tag, CurrentPersonId);
                tagService.Save(tag, CurrentPersonId);
            }

            BindGrid();
        }
Пример #4
0
        /// <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)
        {
            var tagService = new Rock.Model.TagService();
            var tag        = tagService.Get(int.Parse(hfId.Value));

            if (tag != null)
            {
                string errorMessage;
                if (!tagService.CanDelete(tag, out errorMessage))
                {
                    mdDeleteWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                tagService.Delete(tag, CurrentPersonId);
                tagService.Save(tag, CurrentPersonId);

                NavigateToParentPage();
            }
        }
Пример #5
0
        /// <summary>
        /// Handles the Delete event of the rGrid 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 rGrid_Delete(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            var tagService  = new Rock.Model.TagService(rockContext);
            var tag         = tagService.Get(e.RowKeyId);

            if (tag != null)
            {
                string errorMessage;
                if (!tagService.CanDelete(tag, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                tagService.Delete(tag);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
        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 );
        }
Пример #7
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)
        {
            Tag tag;

            using (new Rock.Data.UnitOfWorkScope())
            {
                var tagService = new Rock.Model.TagService();

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

                if (tagId == 0)
                {
                    tag          = new Tag();
                    tag.IsSystem = false;
                    tagService.Add(tag, CurrentPersonId);
                }
                else
                {
                    tag = tagService.Get(tagId);
                }

                tag.Name         = tbName.Text;
                tag.OwnerId      = ppOwner.PersonId;
                tag.EntityTypeId = ddlEntityType.SelectedValueAsId().Value;
                tag.EntityTypeQualifierColumn = tbEntityTypeQualifierColumn.Text;
                tag.EntityTypeQualifierValue  = tbEntityTypeQualifierValue.Text;

                tagService.Save(tag, CurrentPersonId);
            }

            var qryParams = new Dictionary <string, string>();

            qryParams["tagId"] = tag.Id.ToString();

            NavigateToPage(this.CurrentPage.Guid, qryParams);
        }
Пример #8
0
        /// <summary>
        /// Handles the Delete event of the rGrid 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 rGrid_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            var tagService = new Rock.Model.TagService( rockContext );
            var tag = tagService.Get( (int)rGrid.DataKeys[e.RowIndex]["id"] );

            if ( tag != null )
            {
                string errorMessage;
                if ( !tagService.CanDelete( tag, out errorMessage ) )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                tagService.Delete( tag );
                rockContext.SaveChanges();
            }

            BindGrid();
        }
        public HttpResponseMessage Post( int entityTypeId, int ownerId, Guid entityGuid, string name, string entityQualifier, string entityQualifierValue )
        {
            SetProxyCreation( true );

            var personAlias = GetPersonAlias();

            var tagService = new TagService( (Rock.Data.RockContext)Service.Context );

            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.OwnerPersonAliasId = new PersonAliasService( (Rock.Data.RockContext)Service.Context ).GetPrimaryAliasId( ownerId );
                tag.Name = name;
                tagService.Add( tag );
            }

            tag.TaggedItems = tag.TaggedItems ?? new Collection<TaggedItem>();

            var taggedItem = tag.TaggedItems.FirstOrDefault( i => i.EntityGuid.Equals( entityGuid ) );
            if ( taggedItem == null )
            {
                taggedItem = new TaggedItem();
                taggedItem.Tag = tag;
                taggedItem.EntityGuid = entityGuid;
                tag.TaggedItems.Add( taggedItem );
            }

            System.Web.HttpContext.Current.Items.Add( "CurrentPerson", GetPerson() );
            Service.Context.SaveChanges();

            return ControllerContext.Request.CreateResponse( HttpStatusCode.Created );
        }
Пример #10
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();
            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.OwnerPersonAlias == null && !ownerId.HasValue) ||
                           (t.OwnerPersonAlias != null && ownerId.HasValue && t.OwnerPersonAlias.PersonId == ownerId.Value)
                       ) &&
                       (!t.EntityTypeId.HasValue || (
                            t.EntityTypeId.Value == 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
            {
                int?ownerPersonAliasId = null;
                if (ownerId.HasValue)
                {
                    ownerPersonAliasId = new PersonAliasService(rockContext).GetPrimaryAliasId(ownerId.Value);
                }
                tag.Name            = name;
                tag.Description     = tbDescription.Text;
                tag.IsActive        = cbIsActive.Checked;
                tag.IconCssClass    = tbIconCssClass.Text;
                tag.BackgroundColor = cpBackground.Value;
                if (_canConfigure)
                {
                    tag.CategoryId                = cpCategory.SelectedValueAsInt();
                    tag.OwnerPersonAliasId        = ownerPersonAliasId;
                    tag.EntityTypeId              = entityTypeId;
                    tag.EntityTypeQualifierColumn = qualifierCol;
                    tag.EntityTypeQualifierValue  = qualifierVal;
                }

                avcAttributes.GetEditValues(tag);
                // only save if everything saves:
                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    tag.SaveAttributeValues();
                });

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

                NavigateToPage(RockPage.Guid, qryParams);
            }
        }
Пример #11
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.OwnerPersonAlias == null && !ownerId.HasValue ) ||
                            ( t.OwnerPersonAlias != null && ownerId.HasValue && t.OwnerPersonAlias.PersonId == ownerId.Value )
                        ) &&
                        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
            {
                int? ownerPersonAliasId = null;
                if (ownerId.HasValue)
                {
                    ownerPersonAliasId = new PersonAliasService( rockContext ).GetPrimaryAliasId( ownerId.Value );
                }
                tag.Name = name;
                tag.Description = tbDescription.Text;
                tag.OwnerPersonAliasId = ownerPersonAliasId;
                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 );
            }
        }
Пример #12
0
        /// <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 )
        {
            var rockContext = new RockContext();
            var tagService = new Rock.Model.TagService( rockContext );
            var tag = tagService.Get( int.Parse( hfId.Value ) );

            if ( tag != null )
            {
                string errorMessage;
                if ( !tagService.CanDelete( tag, out errorMessage ) )
                {
                    mdDeleteWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                tagService.Delete( tag );
                rockContext.SaveChanges();

                NavigateToParentPage();
            }
        }
Пример #13
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();
            }
        }
Пример #14
0
 public IQueryable<Tag> AvailableNames( int entityTypeId, int ownerId, Guid entityGuid, string entityQualifier, string entityQualifierValue )
 {
     var service = new TagService();
     return service.Get( entityTypeId, entityQualifier, entityQualifierValue, ownerId )
         .Where( t => t.TaggedItems.Select( i => i.EntityGuid ).Contains( entityGuid ) == false )
         .OrderBy( t => t.Name );
 }
Пример #15
0
        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 );
        }
Пример #16
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 )
        {
            Tag tag;

            using ( new Rock.Data.UnitOfWorkScope() )
            {
                var tagService = new Rock.Model.TagService();

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

                if ( tagId == 0 )
                {
                    tag = new Tag();
                    tag.IsSystem = false;
                    tagService.Add( tag, CurrentPersonId );
                }
                else
                {
                    tag = tagService.Get( tagId );
                }

                tag.Name = tbName.Text;
                tag.OwnerId = ppOwner.PersonId;
                tag.EntityTypeId = ddlEntityType.SelectedValueAsId().Value;
                tag.EntityTypeQualifierColumn = tbEntityTypeQualifierColumn.Text;
                tag.EntityTypeQualifierValue = tbEntityTypeQualifierValue.Text;

                tagService.Save( tag, CurrentPersonId );

            }

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

            NavigateToPage( RockPage.Guid, qryParams );
        }