public virtual void Delete(TEntity entityToDelete) { if (_context.Entry(entityToDelete).State == EntityState.Detached) { _dbSet.Attach(entityToDelete); } // Add support for ISupportActivateEntity ISupportActive entity = entityToDelete as ISupportActive; if (entity != null) { if (entity.Active) { entity.Active = false; } } else { ISupportSoftDelete entSoftDel = entityToDelete as ISupportSoftDelete; if (entSoftDel != null) { if (!entSoftDel.Deleted) { entSoftDel.Deleted = true; } } else { _dbSet.Remove(entityToDelete); } } }
public virtual TEntity GetByID(object id, bool includeDeleted = false) { TEntity entity = _dbSet.Find(id); if (entity != null) { ISupportActive activeEntity = entity as ISupportActive; if (activeEntity != null) { if (!activeEntity.Active && !includeDeleted) { entity = null; } } else { ISupportSoftDelete softDelEntity = entity as ISupportSoftDelete; if (softDelEntity != null) { if (softDelEntity.Deleted && !includeDeleted) { entity = null; } } } } return(entity); }
public virtual TEntity Insert(TEntity entity) { BeforeInsert(entity); if (typeof(ISupportActive).IsAssignableFrom(typeof(TEntity))) { ISupportActive e = (ISupportActive)entity; e.Active = true; } return(_dbSet.Add(entity)); }