Beispiel #1
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="entry"></param>
        public override void PreSaveChanges(Data.DbContext dbContext, DbEntityEntry entry)
        {
            var rockContext = ( RockContext )dbContext;
            BinaryFileService binaryFileService = new BinaryFileService(( RockContext )dbContext);
            var binaryFile = binaryFileService.Get(BinaryFileId);

            if (binaryFile != null)
            {
                switch (entry.State)
                {
                case EntityState.Added:
                case EntityState.Modified:
                {
                    binaryFile.IsTemporary = false;

                    break;
                }

                case EntityState.Deleted:
                {
                    var isAttachmentInUse = new CommunicationAttachmentService(( RockContext )dbContext)
                                            .Queryable()
                                            .Where(a => a.BinaryFileId == this.BinaryFileId)
                                            .Any();
                    if (!isAttachmentInUse)
                    {
                        binaryFile.IsTemporary = true;
                    }
                    break;
                }
                }
            }

            base.PreSaveChanges(dbContext, entry);
        }
Beispiel #2
0
            /// <summary>
            /// Called before the save operation is executed.
            /// </summary>
            protected override void PreSave()
            {
                var rockContext = ( RockContext )this.RockContext;
                BinaryFileService binaryFileService = new BinaryFileService(rockContext);
                var binaryFile = binaryFileService.Get(this.Entity.BinaryFileId);

                if (binaryFile != null)
                {
                    switch (State)
                    {
                    case EntityContextState.Added:
                    case EntityContextState.Modified:
                    {
                        binaryFile.IsTemporary = false;

                        break;
                    }

                    case EntityContextState.Deleted:
                    {
                        var isAttachmentInUse = new CommunicationAttachmentService(rockContext)
                                                .Queryable()
                                                .Where(a => a.BinaryFileId == Entity.BinaryFileId)
                                                .Any();
                        if (!isAttachmentInUse)
                        {
                            binaryFile.IsTemporary = true;
                        }
                        break;
                    }
                    }
                }

                base.PreSave();
            }