public void Save(EntityType entityType, int entityId, FileEntity file) { using (DatabaseContext context = CreateDatabaseContext()) { FileRepository fileRepository = new FileRepository(context); VEntityFile entityFile = fileRepository.Save(entityType, entityId, file); context.SaveChanges(); if (entityFile != null) { file.FileId = entityFile.File.FileId; } } }
public VEntityFile Save(EntityType entityType, int entityId, FileEntity file, Action <VEntityFile> onUpdate = null) { TEntity entity = GetEntity(entityType, entityId); if (entity == null) { ThrowEntityNotFoundException(entityType, entityId); } VEntityFile entityFile = GetEntityFile(entityType, entityId, file); if (entityFile == null) { VFile vfile = new VFile(file); entityFile = new VEntityFile(entity, vfile); _databaseContext.EntityFile.Add(entityFile); } else { onUpdate?.Invoke(entityFile); } return(entityFile); }