コード例 #1
0
ファイル: Note.cs プロジェクト: waldo2590/Rock
        /// <summary>
        /// Method that will be called on an entity immediately after the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entry">The entry.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Data.DbContext dbContext, DbEntityEntry entry, EntityState state)
        {
            if (state == EntityState.Added)
            {
                var noteType = NoteTypeCache.Get(this.NoteTypeId);
                if (noteType?.AutoWatchAuthors == true)
                {
                    // if this is a new note, and AutoWatchAuthors, then add a NoteWatch so the author will get notified when there are any replies
                    var rockContext = dbContext as RockContext;
                    if (rockContext != null && this.CreatedByPersonAliasId.HasValue)
                    {
                        var noteWatchService = new NoteWatchService(rockContext);

                        // we don't know the Note.Id yet, so just assign the NoteWatch.Note and EF will populate the NoteWatch.NoteId automatically
                        var noteWatch = new NoteWatch
                        {
                            IsWatching           = true,
                            WatcherPersonAliasId = this.CreatedByPersonAliasId.Value,
                            Note = this
                        };

                        noteWatchService.Add(noteWatch);
                    }
                }
            }

            base.PreSaveChanges(dbContext, entry, state);
        }
コード例 #2
0
            /// <summary>
            /// Creates a <see cref="NoteWatch"/> for the author of this <see cref="Note"/> when appropriate.
            /// </summary>
            private void CreateAutoWatchForAuthor()
            {
                if (State != EntityContextState.Added)
                {
                    return; // only create new watches for new notes.
                }

                var noteType = NoteTypeCache.Get(this.Entity.NoteTypeId);

                if (noteType == null)
                {
                    return; // Probably an error, but let's avoid creating another one.
                }

                if (noteType.AutoWatchAuthors != true)
                {
                    return; // Don't auto watch.
                }

                if (!this.Entity.CreatedByPersonAliasId.HasValue)
                {
                    return; // No author to add a watch for.
                }

                // add a NoteWatch so the author will get notified when there are any replies
                var noteWatch = new NoteWatch
                {
                    // we don't know the Note.Id yet, so just assign the NoteWatch.Note and EF will populate the NoteWatch.NoteId automatically
                    Note                 = this.Entity,
                    IsWatching           = true,
                    WatcherPersonAliasId = this.Entity.CreatedByPersonAliasId.Value
                };

                new NoteWatchService(RockContext).Add(noteWatch);
            }
コード例 #3
0
ファイル: NoteWatchService.cs プロジェクト: waldo2590/Rock
 /// <summary>
 /// Clones this NoteWatch object to a new NoteWatch object
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param>
 /// <returns></returns>
 public static NoteWatch Clone(this NoteWatch source, bool deepCopy)
 {
     if (deepCopy)
     {
         return(source.Clone() as NoteWatch);
     }
     else
     {
         var target = new NoteWatch();
         target.CopyPropertiesFrom(source);
         return(target);
     }
 }
コード例 #4
0
ファイル: NoteWatchService.cs プロジェクト: waldo2590/Rock
 /// <summary>
 /// Copies the properties from another NoteWatch object to this NoteWatch object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this NoteWatch target, NoteWatch source)
 {
     target.Id                      = source.Id;
     target.AllowOverride           = source.AllowOverride;
     target.EntityId                = source.EntityId;
     target.EntityTypeId            = source.EntityTypeId;
     target.ForeignGuid             = source.ForeignGuid;
     target.ForeignKey              = source.ForeignKey;
     target.IsWatching              = source.IsWatching;
     target.NoteId                  = source.NoteId;
     target.NoteTypeId              = source.NoteTypeId;
     target.WatcherGroupId          = source.WatcherGroupId;
     target.WatcherPersonAliasId    = source.WatcherPersonAliasId;
     target.WatchReplies            = source.WatchReplies;
     target.CreatedDateTime         = source.CreatedDateTime;
     target.ModifiedDateTime        = source.ModifiedDateTime;
     target.CreatedByPersonAliasId  = source.CreatedByPersonAliasId;
     target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId;
     target.Guid                    = source.Guid;
     target.ForeignId               = source.ForeignId;
 }