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