diff --git a/zero.Core/Collections/Media/MediaCollection.cs b/zero.Core/Collections/Media/MediaCollection.cs
index 1159de16..d58503ce 100644
--- a/zero.Core/Collections/Media/MediaCollection.cs
+++ b/zero.Core/Collections/Media/MediaCollection.cs
@@ -43,6 +43,10 @@ namespace zero.Core.Collections
///
public async Task GetSourceById(string id, bool thumb = false)
{
+ if (id.StartsWith(Constants.Database.CoreIdPrefix))
+ {
+ ApplyScope("shared");
+ }
IMedia media = await Session.LoadAsync(id);
if (media == null)
diff --git a/zero.Core/Constants.cs b/zero.Core/Constants.cs
index ea528e5d..cd031b41 100644
--- a/zero.Core/Constants.cs
+++ b/zero.Core/Constants.cs
@@ -36,6 +36,7 @@
public static class Database
{
public const string ReservationPrefix = "zero.";
+ public const string CoreIdPrefix = "core.";
public const string Expires = Raven.Client.Constants.Documents.Metadata.Expires;
}
diff --git a/zero.Core/Entities/Media/Media.cs b/zero.Core/Entities/Media/Media.cs
index 10d8ae4c..3782301b 100644
--- a/zero.Core/Entities/Media/Media.cs
+++ b/zero.Core/Entities/Media/Media.cs
@@ -38,6 +38,9 @@ namespace zero.Core.Entities
///
public MediaType Type { get; set; }
+
+ ///
+ public bool IsCore { get; set; }
}
@@ -101,5 +104,10 @@ namespace zero.Core.Entities
/// Type of the media
///
MediaType Type { get; set; }
+
+ ///
+ /// Whether this media item is part of the core database (for multi-tenant setup)
+ ///
+ bool IsCore { get; set; }
}
}
diff --git a/zero.Core/Entities/Media/MediaFolder.cs b/zero.Core/Entities/Media/MediaFolder.cs
index 72335521..4c04cc34 100644
--- a/zero.Core/Entities/Media/MediaFolder.cs
+++ b/zero.Core/Entities/Media/MediaFolder.cs
@@ -7,6 +7,9 @@ namespace zero.Core.Entities
{
///
public string ParentId { get; set; }
+
+ ///
+ public bool IsCore { get; set; }
}
@@ -20,5 +23,10 @@ namespace zero.Core.Entities
/// Parent folder id
///
string ParentId { get; set; }
+
+ ///
+ /// Whether this media folder is part of the core database (for multi-tenant setup)
+ ///
+ bool IsCore { get; set; }
}
}
\ No newline at end of file
diff --git a/zero.Core/Entities/User/BackofficeUser.cs b/zero.Core/Entities/User/BackofficeUser.cs
index 29d6d7d1..d2f0b8c0 100644
--- a/zero.Core/Entities/User/BackofficeUser.cs
+++ b/zero.Core/Entities/User/BackofficeUser.cs
@@ -77,7 +77,7 @@ namespace zero.Core.Entities
}
- [Collection("BackofficeUsers")]
+ [Collection("Users")]
public interface IBackofficeUser : IZeroEntity, IZeroDbConventions, IIdentityUserWithRoles
{
///
diff --git a/zero.Core/Entities/User/BackofficeUserRole.cs b/zero.Core/Entities/User/BackofficeUserRole.cs
index b7b40cf6..9e81965f 100644
--- a/zero.Core/Entities/User/BackofficeUserRole.cs
+++ b/zero.Core/Entities/User/BackofficeUserRole.cs
@@ -17,7 +17,7 @@ namespace zero.Core.Entities
}
- [Collection("BackofficeUserRoles")]
+ [Collection("Roles")]
public interface IBackofficeUserRole : IZeroEntity, IZeroDbConventions, IIdentityUserRole
{
///
diff --git a/zero.Core/Extensions/RavenDocumentStoreExtensions.cs b/zero.Core/Extensions/RavenDocumentStoreExtensions.cs
index 8f889893..c1c9860d 100644
--- a/zero.Core/Extensions/RavenDocumentStoreExtensions.cs
+++ b/zero.Core/Extensions/RavenDocumentStoreExtensions.cs
@@ -16,6 +16,7 @@ namespace zero.Core.Extensions
public static class RavenDocumentStoreExtensions
{
const char DOT = '.';
+
///
/// Setup conventions for the document store
///
@@ -29,10 +30,22 @@ namespace zero.Core.Extensions
store.Conventions.RegisterAsyncIdConvention((_, entity) =>
{
+ string prefix = String.Empty;
+ string guid = IdGenerator.Create();
string collection = store.Conventions.GetCollectionName(entity);
//CollectionAttribute collectionAttribute = entity.GetType().GetCustomAttribute(true);
+
+ if ((entity is IMedia && ((IMedia)entity).IsCore) || (entity is IMediaFolder && ((IMediaFolder)entity).IsCore))
+ {
+ prefix = Constants.Database.CoreIdPrefix;
+ }
+ if (entity is IBackofficeUser or IBackofficeUserRole)
+ {
+ guid = IdGenerator.Create(8);
+ }
+
string tag = store.Conventions.TransformTypeCollectionNameToDocumentIdPrefix(collection);
- return Task.FromResult(tag + store.Conventions.IdentityPartsSeparator + IdGenerator.Create());
+ return Task.FromResult(prefix + tag + store.Conventions.IdentityPartsSeparator + guid);
});
store.Conventions.RegisterAsyncIdConvention((_, entity) =>