/// <summary> /// Removes a PropertyType from the current ContentType when user clicks "red x" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gpw_Delete(object sender, EventArgs e) { var state = new DeleteAsyncState( UmbracoContext, (GenericPropertyWrapper)sender); //Add the async operation to the page Page.RegisterAsyncTask(new PageAsyncTask(BeginAsyncDeleteOperation, EndAsyncDeleteOperation, HandleAsyncSaveTimeout, state)); //create the save task to be executed async _asyncDeleteTask = asyncState => { Trace.Write("ContentTypeControlNew", "executing task"); //we need to re-set the UmbracoContext since it will be nulled and our cache handlers need it global::Umbraco.Web.UmbracoContext.Current = asyncState.UmbracoContext; if (_contentType.ContentTypeItem is IContentType || _contentType.ContentTypeItem is IMediaType) { _contentType.ContentTypeItem.RemovePropertyType(asyncState.GenericPropertyWrapper.PropertyType.Alias); _contentType.Save(); } else { //if it is not a document type or a media type, then continue to call the legacy delete() method. //the new API for document type and media type's will ensure that the data is removed correctly and that //the cache is flushed correctly (using events). If it is not one of these types, we'll rever to the //legacy operation (... like for members i suppose ?) asyncState.GenericPropertyWrapper.GenricPropertyControl.PropertyType.delete(); } Trace.Write("ContentTypeControlNew", "task completing"); }; //execute the async tasks Page.ExecuteRegisteredAsyncTasks(); }
/// <summary> /// Removes a PropertyType from the current ContentType when user clicks "red x" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gpw_Delete(object sender, EventArgs e) { var state = new DeleteAsyncState( Umbraco.Web.UmbracoContext.Current, (GenericPropertyWrapper)sender); //Add the async operation to the page Page.RegisterAsyncTask(new PageAsyncTask(BeginAsyncDeleteOperation, EndAsyncDeleteOperation, HandleAsyncSaveTimeout, state)); //create the save task to be executed async _asyncDeleteTask = asyncState => { Trace.Write("ContentTypeControlNew", "executing task"); //we need to re-set the UmbracoContext since it will be nulled and our cache handlers need it global::Umbraco.Web.UmbracoContext.Current = asyncState.UmbracoContext; if (_contentType.ContentTypeItem is IContentType || _contentType.ContentTypeItem is IMediaType) { _contentType.ContentTypeItem.RemovePropertyType(asyncState.GenericPropertyWrapper.PropertyType.Alias); _contentType.Save(); } //delete the property asyncState.GenericPropertyWrapper.GenricPropertyControl.PropertyType.delete(); //we need to re-generate the xml structures because we're removing a content type property RegenerateXmlCaches(); Trace.Write("ContentTypeControlNew", "task completing"); }; //execute the async tasks Page.ExecuteRegisteredAsyncTasks(); }