public static async Task <EntityEntry <E> > ReloadAsyncDefault <E>(this IFullAuditableDbContext dbContext, E entity) where E : class
        {
            var entry = dbContext.Entry(entity);

            await entry.ReloadAsync();

            return(entry);
        }
        public static bool TryAttachDefault(this IFullAuditableDbContext dbContext, object entity, out EntityEntry entry)
        {
            entry = dbContext.Entry(entity);

            if (entry.State == EntityState.Detached)
            {
                entry = dbContext.Attach(entity);

                return(true);
            }

            return(false);
        }
        public static EntityEntry SoftDeleteDefault(this IFullAuditableDbContext dbContext, object entity)
        {
            if (entity is ISoftDeleteEntity softDeleteEntity)
            {
                softDeleteEntity.IsDeleted = true;

                var entry = dbContext.Entry(entity);
                entry.Property(nameof(softDeleteEntity.IsDeleted)).IsModified = true;

                return(entry);
            }

            throw new InvalidOperationException($"{nameof(entity)} is not {nameof(ISoftDeleteEntity)}");
        }
        public static bool TryAttachDefault <T>(this IFullAuditableDbContext dbContext, T entity, out EntityEntry <T> entry)
            where T : class
        {
            entry = dbContext.Entry(entity);

            if (entry.State == EntityState.Detached)
            {
                entry = dbContext.Attach(entity);

                return(true);
            }

            return(false);
        }
Beispiel #5
0
        public static EntityEntry SoftRemoveDefault(this IFullAuditableDbContext dbContext, object entity)
        {
            if (entity is ISoftDeleteEntity == false)
            {
                throw new InvalidOperationException($"{nameof(entity)} is not {nameof(ISoftDeleteEntity)}");
            }

            var softDeleteEntity = entity as ISoftDeleteEntity;

            softDeleteEntity.IsDeleted = true;

            var entry = dbContext.Entry(entity);

            entry.State = EntityState.Modified;

            return(entry);
        }