/// <summary> /// Sendings to publish event handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="SendToPublishEventArgs{IContent}"/> instance containing the event data.</param> private void SendingToPublishEventHandler(IContentService sender, SendToPublishEventArgs <IContent> args) { if (args == null || args.Entity == null || args.Entity.Properties == null || args.Entity.Properties.Count == 0) { return; } // Get user making changes IUser user = UmbracoContext.Current.Security.CurrentUser; // Fetch original content IContent originalContent = UmbracoContext.Current.Application.Services.ContentService.GetById(args.Entity.Id); // Get the Umbraco db var db = UmbracoContext.Current.Application.DatabaseContext.Database; // Start a transaction using (var scope = db.GetTransaction()) { DateTime now = DateTime.Now; // Find which properties were actually changed IList <Property> dirtyProps = args.Entity.Properties.ToList(); foreach (Property dirtyProp in dirtyProps) { Property originalProp = originalContent.Properties .Where(x => x.Id == dirtyProp.Id) .FirstOrDefault(); if (originalProp != null && originalProp.Value != null && string.Compare(originalProp.Value.ToString(), dirtyProp.Value.ToString(), false) != 0) { // Creates a new change history table item ChangeHistory newChange = new ChangeHistory(); newChange.PropertyId = dirtyProp.Id; newChange.PropertyAlias = dirtyProp.Alias; newChange.NodeId = args.Entity.Id; newChange.UpdateDate = now; newChange.UpdatedBy = user.Username; newChange.PreviousValue = originalProp.Value.ToString(); newChange.CurrentValue = dirtyProp.Value.ToString(); newChange.PropertyTypeAlias = dirtyProp.PropertyType.PropertyEditorAlias; db.Insert(newChange); } } // Commit the transaction scope.Complete(); } }
/// <summary> /// Executes handlers and events for the Send To Publication action. /// </summary> /// <param name="u">The User</param> public bool SendToPublication(User u) { SendToPublishEventArgs e = new SendToPublishEventArgs(); FireBeforeSendToPublish(e); if (!e.Cancel) { BusinessLogic.Log.Add(BusinessLogic.LogTypes.SendToPublish, u, this.Id, ""); BusinessLogic.Actions.Action.RunActionHandlers(this, ActionToPublish.Instance); FireAfterSendToPublish(e); return true; } return false; }
/// <summary> /// Raises the <see cref="E:AfterPublish"/> event. /// </summary> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected virtual void FireAfterSendToPublish(SendToPublishEventArgs e) { if (AfterSendToPublish != null) AfterSendToPublish(this, e); }
/// <summary> /// Raises the <see cref="E:BeforePublish"/> event. /// </summary> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected virtual void FireBeforeSendToPublish(SendToPublishEventArgs e) { if (BeforeSendToPublish != null) BeforeSendToPublish(this, e); }
public virtual void SendingToPublish(IContentService contentService, SendToPublishEventArgs <IContent> args) { }
/// <summary> /// Executes handlers and events for the Send To Publication action. /// </summary> /// <param name="u">The User</param> public bool SendToPublication(User u) { var e = new SendToPublishEventArgs(); FireBeforeSendToPublish(e); if (e.Cancel == false) { var sent = ApplicationContext.Current.Services.ContentService.SendToPublication(Content, u.Id); if (sent) { FireAfterSendToPublish(e); return true; } } return false; }
void ContentService_SentToPublish(IContentService sender, SendToPublishEventArgs<IContent> e) { RefreshArticle(e.Entity); }