diff --git a/zero.Core/Api/ApplicationsApi.cs b/zero.Core/Api/ApplicationsApi.cs index 19cd16b0..a3f16323 100644 --- a/zero.Core/Api/ApplicationsApi.cs +++ b/zero.Core/Api/ApplicationsApi.cs @@ -10,54 +10,54 @@ namespace zero.Core.Api { public class ApplicationsApi : BackofficeApi, IApplicationsApi { - IValidator Validator; + IValidator Validator; - public ApplicationsApi(IBackofficeStore store, IValidator validator) : base(store, isCoreDatabase: true) + public ApplicationsApi(IBackofficeStore store, IValidator validator) : base(store, isCoreDatabase: true) { Validator = validator; } /// - public async Task GetById(string id) + public async Task GetById(string id) { - return await GetById(id); + return await GetById(id); } /// - public async Task> GetAll() + public async Task> GetAll() { using IAsyncDocumentSession session = Session(); return await session - .Query() + .Query() .OrderByDescending(x => x.CreatedDate) .ToListAsync(); } /// - public async Task> GetByQuery(ListQuery query) + public async Task> GetByQuery(ListQuery query) { query.SearchFor(entity => entity.Name); using IAsyncDocumentSession session = Session(); - return await session.Query().ToQueriedListAsync(query); + return await session.Query().ToQueriedListAsync(query); } /// - public async Task> Save(IApplication model) + public async Task> Save(Application model) { return await SaveModel(model, Validator); } /// - public async Task> Delete(string id) + public async Task> Delete(string id) { - return await DeleteById(id); + return await DeleteById(id); } } @@ -67,26 +67,26 @@ namespace zero.Core.Api /// /// Get application by Id /// - Task GetById(string id); + Task GetById(string id); /// /// Get all available zero applications /// - Task> GetAll(); + Task> GetAll(); /// /// Get all available applications (with query) /// - Task> GetByQuery(ListQuery query); + Task> GetByQuery(ListQuery query); /// /// Creates or updates a application /// - Task> Save(IApplication model); + Task> Save(Application model); /// /// Deletes a application by Id /// - Task> Delete(string id); + Task> Delete(string id); } } diff --git a/zero.Core/Api/AuthenticationApi.cs b/zero.Core/Api/AuthenticationApi.cs index 79dc9fe9..bcc7b144 100644 --- a/zero.Core/Api/AuthenticationApi.cs +++ b/zero.Core/Api/AuthenticationApi.cs @@ -141,7 +141,7 @@ namespace zero.Core.Api /// public async Task TrySwitchApp(string appId) { - IBackofficeUser user = await GetUser(); + BackofficeUser user = await GetUser(); if (user == null || appId.IsNullOrEmpty()) { diff --git a/zero.Core/Api/AuthorizationApi.cs b/zero.Core/Api/AuthorizationApi.cs index a5561022..74740c81 100644 --- a/zero.Core/Api/AuthorizationApi.cs +++ b/zero.Core/Api/AuthorizationApi.cs @@ -76,7 +76,7 @@ namespace zero.Core.Api } - public EntityPermission GetPermissionForEntity(T model, string permissionKey) where T : IZeroEntity + public EntityPermission GetPermissionForEntity(T model, string permissionKey) where T : ZeroEntity { EntityPermission result = new EntityPermission(); diff --git a/zero.Core/Api/BackofficeApi.cs b/zero.Core/Api/BackofficeApi.cs index 67d6b36e..00e6688e 100644 --- a/zero.Core/Api/BackofficeApi.cs +++ b/zero.Core/Api/BackofficeApi.cs @@ -53,7 +53,7 @@ namespace zero.Core.Api /// - public async Task GetById(string id) where T : IZeroIdEntity + public async Task GetById(string id) where T : ZeroIdEntity { if (id.IsNullOrWhiteSpace()) { @@ -66,7 +66,7 @@ namespace zero.Core.Api /// - public async Task> GetByIds(params string[] ids) where T : IZeroIdEntity + public async Task> GetByIds(params string[] ids) where T : ZeroIdEntity { using IAsyncDocumentSession session = Session(); Dictionary models = await session.LoadAsync(ids); @@ -84,7 +84,7 @@ namespace zero.Core.Api /// - public async Task> SaveModel(T model, IValidator validator = null, Action meta = null) where T : IZeroEntity + public async Task> SaveModel(T model, IValidator validator = null, Action meta = null) where T : ZeroEntity { // check for alias //if (model is IUrlAliasEntity) @@ -150,11 +150,7 @@ namespace zero.Core.Api { model.CreatedDate = DateTimeOffset.Now; model.CreatedById = userId; - - if (model is ILanguageAwareEntity) - { - (model as ILanguageAwareEntity).LanguageId = "languages.1-A"; // TODO correct language id - } + model.LanguageId = "languages.1-A"; // TODO correct language id } // update name alias and last modified @@ -179,7 +175,7 @@ namespace zero.Core.Api /// - public async Task> DeleteById(string id) where T : IZeroIdEntity + public async Task> DeleteById(string id) where T : ZeroIdEntity { using IAsyncDocumentSession session = Session(); session.Advanced.WaitForIndexesAfterSaveChanges(throwOnTimeout: false); @@ -200,7 +196,7 @@ namespace zero.Core.Api /// - public async Task DeleteByIds(params string[] ids) where T : IZeroIdEntity + public async Task DeleteByIds(params string[] ids) where T : ZeroIdEntity { int successCount = 0; @@ -230,28 +226,28 @@ namespace zero.Core.Api /// Get an entity by Id. /// If the requested entity is an IAppAwareEntity it will only return entities for the currently selected app + shared app /// - Task GetById(string id) where T : IZeroIdEntity; + Task GetById(string id) where T : ZeroIdEntity; /// /// Get entities by ids. /// If the requested entity is an IAppAwareEntity it will only return entities for the currently selected app + shared app /// - Task> GetByIds(params string[] ids) where T : IZeroIdEntity; + Task> GetByIds(params string[] ids) where T : ZeroIdEntity; /// /// Updates or creates an entity with an optional validator /// - Task> SaveModel(T model, IValidator validator = null, Action meta = null) where T : IZeroEntity; + Task> SaveModel(T model, IValidator validator = null, Action meta = null) where T : ZeroEntity; /// /// Deletes an entity by Id /// - Task> DeleteById(string id) where T : IZeroIdEntity; + Task> DeleteById(string id) where T : ZeroIdEntity; /// /// Deletes entities by Id /// - Task DeleteByIds(params string[] ids) where T : IZeroIdEntity; + Task DeleteByIds(params string[] ids) where T : ZeroIdEntity; /// /// Delete a whole collection (with an optional query suffix, i.e. a where statement) diff --git a/zero.Core/Api/ExportApi.cs b/zero.Core/Api/ExportApi.cs index d7ac8929..7a9b35a4 100644 --- a/zero.Core/Api/ExportApi.cs +++ b/zero.Core/Api/ExportApi.cs @@ -31,6 +31,6 @@ // /// // /// Returns a space by a defined generic // /// -// Space GetBy() where T : ISpaceContent; +// Space GetBy() where T : SpaceContent; // } //} diff --git a/zero.Core/Api/MediaApi.cs b/zero.Core/Api/MediaApi.cs index 9354f088..43c5d093 100644 --- a/zero.Core/Api/MediaApi.cs +++ b/zero.Core/Api/MediaApi.cs @@ -39,7 +39,7 @@ namespace zero.Core.Api /// - public async Task GetById(string id) + public async Task GetById(string id) { return await GetById(id); } @@ -50,7 +50,7 @@ namespace zero.Core.Api { using IAsyncDocumentSession session = isCoreDatabase ? Store.OpenCoreSession() : Store.OpenAsyncSession(); - IMedia media = await session.LoadAsync(id); + Media media = await session.LoadAsync(id); if (media == null) { @@ -67,23 +67,23 @@ namespace zero.Core.Api /// - public async Task> GetById(IEnumerable ids) + public async Task> GetById(IEnumerable ids) { using (IAsyncDocumentSession session = Store.OpenAsyncSession()) { - return await session.LoadAsync(ids); + return await session.LoadAsync(ids); } } /// - public async Task> GetByQuery(MediaListQuery query) + public async Task> GetByQuery(MediaListQuery query) { query.SearchFor(entity => entity.Name); using (IAsyncDocumentSession session = Store.OpenAsyncSession()) { - return await session.Query() + return await session.Query() .WhereIf(x => x.FolderId == query.FolderId, !query.FolderId.IsNullOrEmpty(), x => x.FolderId == null) .ToQueriedListAsync(query); } @@ -137,7 +137,7 @@ namespace zero.Core.Api /// - public async Task> Save(IMedia model) + public async Task> Save(Media model) { model.IsActive = true; return await SaveModel(model); @@ -145,14 +145,14 @@ namespace zero.Core.Api /// - public async Task> Move(string id, string parentId) + public async Task> Move(string id, string parentId) { - IMedia model = await GetById(id); - IMediaFolder parent = await GetById(parentId); + Media model = await GetById(id); + MediaFolder parent = await GetById(parentId); if (model == null || (!parentId.IsNullOrEmpty() && parent == null)) { - return EntityResult.Fail("@errors.idnotfound"); + return EntityResult.Fail("@errors.idnotfound"); } model.FolderId = parent?.Id; @@ -162,9 +162,9 @@ namespace zero.Core.Api /// - public async Task> Delete(string id) + public async Task> Delete(string id) { - return await DeleteById(id); + return await DeleteById(id); } @@ -237,7 +237,7 @@ namespace zero.Core.Api /// /// Saves a thumbnail of an image /// - string SaveThumbnail(IMedia media, Image image, string extensionPrefix, ResizeOptions resizeOptions) + string SaveThumbnail(Media media, Image image, string extensionPrefix, ResizeOptions resizeOptions) { string extension = Path.GetExtension(media.Source); @@ -275,7 +275,7 @@ namespace zero.Core.Api /// /// Get media by Id /// - Task GetById(string id); + Task GetById(string id); /// /// Get media source by Id @@ -285,12 +285,12 @@ namespace zero.Core.Api /// /// Get media by ids /// - Task> GetById(IEnumerable ids); + Task> GetById(IEnumerable ids); /// /// Get all available media items with query /// - Task> GetByQuery(MediaListQuery query); + Task> GetByQuery(MediaListQuery query); /// /// Get all available media items (including folders) with query @@ -300,17 +300,17 @@ namespace zero.Core.Api /// /// Creates or updates a media item /// - Task> Save(IMedia model); + Task> Save(Media model); /// /// Move a file to a new parent /// - Task> Move(string id, string parentId); + Task> Move(string id, string parentId); /// /// Deletes a media item by Id /// - Task> Delete(string id); + Task> Delete(string id); /// /// Clean-up all media based on stored database information diff --git a/zero.Core/Api/MediaFolderApi.cs b/zero.Core/Api/MediaFolderApi.cs index d7d70b17..762431e9 100644 --- a/zero.Core/Api/MediaFolderApi.cs +++ b/zero.Core/Api/MediaFolderApi.cs @@ -14,28 +14,28 @@ namespace zero.Core.Api { public class MediaFolderApi : BackofficeApi, IMediaFolderApi { - IValidator Validator; + IValidator Validator; - public MediaFolderApi(IBackofficeStore store, IValidator validator) : base(store) + public MediaFolderApi(IBackofficeStore store, IValidator validator) : base(store) { Validator = validator; } /// - public async Task GetById(string id) + public async Task GetById(string id) { - return await GetById(id); + return await GetById(id); } /// - public async Task> GetAll(string parentId = null) + public async Task> GetAll(string parentId = null) { using (IAsyncDocumentSession session = Store.OpenAsyncSession()) { - return await session.Query() + return await session.Query() .WhereIf(x => x.ParentId == parentId, !parentId.IsNullOrEmpty(), x => x.ParentId == null) .OrderByDescending(x => x.Name) .ToListAsync(); @@ -51,7 +51,7 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Store.OpenAsyncSession()) { - IList folders = await session.Query() + IList folders = await session.Query() .WhereIf(x => x.ParentId == parentId, !parentId.IsNullOrEmpty(), x => x.ParentId == null) .OrderByDescending(x => x.CreatedDate).ThenBy(x => x.Name) .ToListAsync(); @@ -62,7 +62,7 @@ namespace zero.Core.Api { MediaFolder_ByHierarchy.Result result = await session.Query() .ProjectInto() - .Include(x => x.Path.Select(p => p.Id)) + .Include(x => x.Path.Select(p => p.Id)) .FirstOrDefaultAsync(x => x.Id == activeId); if (result != null) @@ -81,7 +81,7 @@ namespace zero.Core.Api .ToListAsync(); - foreach (IMediaFolder folder in folders) + foreach (MediaFolder folder in folders) { int childCount = children.Count(x => x.Id == folder.Id); @@ -124,30 +124,30 @@ namespace zero.Core.Api /// - public async Task> GetHierarchy(string id) + public async Task> GetHierarchy(string id) { using (IAsyncDocumentSession session = Store.OpenAsyncSession()) { MediaFolder_ByHierarchy.Result result = await session.Query() .ProjectInto() - .Include(x => x.Path.Select(p => p.Id)) + .Include(x => x.Path.Select(p => p.Id)) .FirstOrDefaultAsync(x => x.Id == id); if (result == null) { - return new List(); + return new List(); } List ids = result.Path.Select(x => x.Id).ToList(); ids.Add(id); - return (await session.LoadAsync(ids)).Select(x => x.Value).ToList(); + return (await session.LoadAsync(ids)).Select(x => x.Value).ToList(); } } /// - public async Task> Save(IMediaFolder model) + public async Task> Save(MediaFolder model) { model.IsActive = true; return await SaveModel(model, Validator); @@ -155,14 +155,14 @@ namespace zero.Core.Api /// - public async Task> Move(string id, string parentId) + public async Task> Move(string id, string parentId) { - IMediaFolder model = await GetById(id); - IMediaFolder parent = await GetById(parentId); + MediaFolder model = await GetById(id); + MediaFolder parent = await GetById(parentId); if (model == null || (!parentId.IsNullOrEmpty() && parent == null)) { - return EntityResult.Fail("@errors.idnotfound"); + return EntityResult.Fail("@errors.idnotfound"); } model.ParentId = parent?.Id; @@ -172,9 +172,9 @@ namespace zero.Core.Api /// - public async Task> Delete(string id) + public async Task> Delete(string id) { - return await DeleteById(id); + return await DeleteById(id); } } @@ -184,17 +184,17 @@ namespace zero.Core.Api /// /// Get application by Id /// - Task GetById(string id); + Task GetById(string id); /// /// Get hierarchy for a folder /// - Task> GetHierarchy(string id); + Task> GetHierarchy(string id); /// /// Get all folders with the specified parent or on root /// - Task> GetAll(string parentId = null); + Task> GetAll(string parentId = null); /// /// Get all folders with the specified parent or on root for tree output @@ -204,16 +204,16 @@ namespace zero.Core.Api /// /// Creates or updates a folder /// - Task> Save(IMediaFolder model); + Task> Save(MediaFolder model); /// /// Move a folder to a new parent /// - Task> Move(string id, string parentId); + Task> Move(string id, string parentId); /// /// Deletes a folder /// - Task> Delete(string id); + Task> Delete(string id); } } diff --git a/zero.Core/Api/ModulesApi.cs b/zero.Core/Api/ModulesApi.cs index 154d0376..8a37f920 100644 --- a/zero.Core/Api/ModulesApi.cs +++ b/zero.Core/Api/ModulesApi.cs @@ -27,11 +27,11 @@ namespace zero.Core.Api { IEnumerable types = Options.Modules.GetAllItems(); List modules = types.ToList(); - IPage page = null; + Page page = null; if (!pageId.IsNullOrEmpty()) { - page = await GetById(pageId); + page = await GetById(pageId); } if (tags?.Length > 0) diff --git a/zero.Core/Api/PageTreeApi.cs b/zero.Core/Api/PageTreeApi.cs index f9fe9bf3..ab48ddda 100644 --- a/zero.Core/Api/PageTreeApi.cs +++ b/zero.Core/Api/PageTreeApi.cs @@ -29,7 +29,7 @@ namespace zero.Core.Api IList items = new List(); IReadOnlyCollection pageTypes = Backoffice.Options.Pages.GetAllItems(); string[] openIds = new string[0] { }; - IList pages = null; + IList pages = null; IList children = null; bool isSearch = !search.IsNullOrWhiteSpace(); @@ -39,14 +39,14 @@ namespace zero.Core.Api if (isSearch) { pages = await session - .Query() + .Query() .SearchIf(x => x.Name, search, "*") .OrderBy(x => x.Sort, OrderingType.Long) .ToListAsync(); var urls = await Routes.GetUrls(pages.ToArray()); - foreach (IPage page in pages) + foreach (Page page in pages) { if (urls.TryGetValue(page, out string url)) { @@ -58,7 +58,7 @@ namespace zero.Core.Api { pages = await session - .Query() + .Query() .WhereIf(x => x.ParentId == parentId, !parentId.IsNullOrEmpty(), x => x.ParentId == null) .OrderBy(x => x.Sort, OrderingType.Long) .ToListAsync(); @@ -90,7 +90,7 @@ namespace zero.Core.Api // function to get modifier icon - TreeItemModifier GetModifier(IPage page) + TreeItemModifier GetModifier(Page page) { if (page.PublishDate > DateTimeOffset.Now || page.UnpublishDate > DateTimeOffset.Now) { @@ -105,7 +105,7 @@ namespace zero.Core.Api // build tree - foreach (IPage page in pages) + foreach (Page page in pages) { PageType pageType = pageTypes.FirstOrDefault(x => x.Alias == page.PageTypeAlias); diff --git a/zero.Core/Api/PagesApi.cs b/zero.Core/Api/PagesApi.cs index c6d5ba23..ceeb48d4 100644 --- a/zero.Core/Api/PagesApi.cs +++ b/zero.Core/Api/PagesApi.cs @@ -38,18 +38,18 @@ namespace zero.Core.Api /// - public Task GetEmpty(string pageType, string parentId = null) + public Task GetEmpty(string pageType, string parentId = null) { PageType type = GetPageType(pageType); if (type == null) { - return Task.FromResult(null); + return Task.FromResult(null); } try { - IPage model = Activator.CreateInstance(type.ContentType) as IPage; + Page model = Activator.CreateInstance(type.ContentType) as Page; model.PageTypeAlias = type.Alias; model.ParentId = parentId; // TODO validate if type is allowed and if parentid is allowed @@ -61,21 +61,21 @@ namespace zero.Core.Api Logger.LogWarning("Could not create page with type {type}", type); } - return Task.FromResult(null); + return Task.FromResult(null); } /// - public async Task GetById(string id) + public async Task GetById(string id) { - return await GetById(id); + return await GetById(id); } /// - public async Task> GetByIds(params string[] ids) + public async Task> GetByIds(params string[] ids) { - return await GetByIds(ids); + return await GetByIds(ids); } @@ -90,7 +90,7 @@ namespace zero.Core.Api public async Task> GetAllowedPageTypes(string parentId = null) { IEnumerable types = Options.Pages.GetAllItems(); - List parents = new(); + List parents = new(); using IAsyncDocumentSession session = Store.OpenAsyncSession(); @@ -98,15 +98,15 @@ namespace zero.Core.Api { Pages_ByHierarchy.Result result = await session.Query() .ProjectInto() - .Include(x => x.Id) - .Include(x => x.Path.Select(p => p.Id)) + .Include(x => x.Id) + .Include(x => x.Path.Select(p => p.Id)) .FirstOrDefaultAsync(x => x.Id == parentId); if (result != null) { List ids = result.Path.Select(x => x.Id).ToList(); ids.Add(result.Id); - parents = (await session.LoadAsync(ids)).Select(x => x.Value).Reverse().ToList(); + parents = (await session.LoadAsync(ids)).Select(x => x.Value).Reverse().ToList(); } } @@ -130,22 +130,22 @@ namespace zero.Core.Api /// - public async Task> Save(IPage model) + public async Task> Save(Page model) { return await SaveModel(model, null); } /// - public async Task>> SaveSorting(string[] sortedIds) + public async Task>> SaveSorting(string[] sortedIds) { - Dictionary items = await GetByIds(sortedIds); + Dictionary items = await GetByIds(sortedIds); uint index = 0; // contains multiple parents, therefore fail if (items.Select(x => x.Value?.ParentId).Distinct().Count() > 1) { - return EntityResult>.Fail("@errors.page.sortingmultipleparents"); + return EntityResult>.Fail("@errors.page.sortingmultipleparents"); } using (IAsyncDocumentSession session = Store.OpenAsyncSession()) @@ -163,26 +163,26 @@ namespace zero.Core.Api await session.SaveChangesAsync(); } - return EntityResult>.Success(items.Select(x => x.Value).ToList()); + return EntityResult>.Success(items.Select(x => x.Value).ToList()); } /// - public async Task> Move(string id, string parentId) + public async Task> Move(string id, string parentId) { - IPage model = await GetById(id); - IPage parent = await GetById(parentId); + Page model = await GetById(id); + Page parent = await GetById(parentId); if (model == null || (!parentId.IsNullOrEmpty() && parent == null)) { - return EntityResult.Fail("@errors.idnotfound"); + return EntityResult.Fail("@errors.idnotfound"); } IList pageTypes = await GetAllowedPageTypes(parentId); if (!pageTypes.Any(x => x.Alias == model.PageTypeAlias)) { - return EntityResult.Fail("@errors.page.parentnotallowed"); + return EntityResult.Fail("@errors.page.parentnotallowed"); } model.ParentId = parent?.Id; @@ -192,14 +192,14 @@ namespace zero.Core.Api /// - public async Task> Copy(string id, string destinationId, bool includeDescendants = false) + public async Task> Copy(string id, string destinationId, bool includeDescendants = false) { - IPage model = await GetById(id); - IPage parent = await GetById(destinationId); + Page model = await GetById(id); + Page parent = await GetById(destinationId); if (model == null || (!destinationId.IsNullOrEmpty() && parent == null)) { - return EntityResult.Fail("@errors.idnotfound"); + return EntityResult.Fail("@errors.idnotfound"); } string baseId = model.Id; @@ -215,7 +215,7 @@ namespace zero.Core.Api if (!pageTypes.Any(x => x.Alias == model.PageTypeAlias)) { - return EntityResult.Fail("@errors.page.parentnotallowed"); + return EntityResult.Fail("@errors.page.parentnotallowed"); } using (IAsyncDocumentSession session = Store.OpenAsyncSession()) @@ -227,7 +227,7 @@ namespace zero.Core.Api { Pages_WithChildren.Result childrenResult = await session.Query() .ProjectInto() - .Include(x => x.Id) + .Include(x => x.Id) .Where(x => x.Id == oldParentId) .FirstOrDefaultAsync(); @@ -236,11 +236,11 @@ namespace zero.Core.Api return; } - Dictionary childrenPages = await session.LoadAsync(childrenResult.ChildrenIds); + Dictionary childrenPages = await session.LoadAsync(childrenResult.ChildrenIds); foreach (var child in childrenPages) { - IPage childPage = child.Value.Clone(); + Page childPage = child.Value.Clone(); childPage.Id = null; childPage.IsActive = false; childPage.ParentId = newParentId; @@ -261,14 +261,14 @@ namespace zero.Core.Api await session.SaveChangesAsync(); } - return EntityResult.Success(model); + return EntityResult.Success(model); } /// public async Task> Delete(string id, bool moveToRecycleBin = true) { - IList pages = await GetByIdWithDescendants(id); + IList pages = await GetByIdWithDescendants(id); string[] ids = pages.Select(x => x.Id).ToArray(); if (pages.Count < 1) @@ -281,7 +281,7 @@ namespace zero.Core.Api await RecycleBinApi.Add(pages, RECYCLE_BIN_GROUP); } - await DeleteByIds(ids); + await DeleteByIds(ids); return EntityResult.Success(ids); } @@ -291,8 +291,8 @@ namespace zero.Core.Api public async Task> Restore(string id, bool includeDescendants = false) { EntityResult result = new EntityResult(); - IRecycledEntity recycledEntity = await RecycleBinApi.GetById(id); - List entities = new List() { recycledEntity }; + RecycledEntity recycledEntity = await RecycleBinApi.GetById(id); + List entities = new List() { recycledEntity }; if (recycledEntity == null) { @@ -309,21 +309,21 @@ namespace zero.Core.Api string[] ids = entities.Select(x => x.OriginalId).ToArray(); // check if parents are available - string[] parentIds = entities.Select(x => x.Content as IPage).Where(x => x != null).Select(x => x.ParentId).ToArray(); - parentIds = (await GetByIds(parentIds)).Where(x => x.Value != null).Select(x => x.Value.Id).ToArray(); + string[] parentIds = entities.Select(x => x.Content as Page).Where(x => x != null).Select(x => x.ParentId).ToArray(); + parentIds = (await GetByIds(parentIds)).Where(x => x.Value != null).Select(x => x.Value.Id).ToArray(); // validate and restore all items - foreach (IRecycledEntity entity in entities) + foreach (RecycledEntity entity in entities) { // check if it contains page data - if (entity.Group != RECYCLE_BIN_GROUP || !(entity.Content is IPage)) + if (entity.Group != RECYCLE_BIN_GROUP || !(entity.Content is Page)) { - //result.AddError("Cannot parse recycled entity as an IPage in group \"" + RECYCLE_BIN_GROUP + "\""); // TODO correct error message + //result.AddError("Cannot parse recycled entity as an Page in group \"" + RECYCLE_BIN_GROUP + "\""); // TODO correct error message continue; } // get page - IPage page = entity.Content as IPage; + Page page = entity.Content as Page; page.IsActive = false; // validate app and parent @@ -334,7 +334,7 @@ namespace zero.Core.Api } // restore to pages - EntityResult saveResult = await SaveModel(page); + EntityResult saveResult = await SaveModel(page); } // delete affected entities from recycle bin @@ -354,11 +354,11 @@ namespace zero.Core.Api /// /// Get a page with all its descendants /// - async Task> GetByIdWithDescendants(string id) + async Task> GetByIdWithDescendants(string id) { - List items = new List(); + List items = new List(); - IPage model = await GetById(id); + Page model = await GetById(id); if (model == null) { @@ -374,7 +374,7 @@ namespace zero.Core.Api { Pages_WithChildren.Result childrenResult = await session.Query() .ProjectInto() - .Include(x => x.Id) + .Include(x => x.Id) .Where(x => x.Id == parentId) .FirstOrDefaultAsync(); @@ -383,7 +383,7 @@ namespace zero.Core.Api return; } - Dictionary childrenPages = await session.LoadAsync(childrenResult.ChildrenIds); + Dictionary childrenPages = await session.LoadAsync(childrenResult.ChildrenIds); foreach (var child in childrenPages) { @@ -405,17 +405,17 @@ namespace zero.Core.Api /// /// Get a new empty page with the specified type /// - public Task GetEmpty(string pageType, string parentId = null); + public Task GetEmpty(string pageType, string parentId = null); /// /// Get page by Id /// - Task GetById(string id); + Task GetById(string id); /// /// Get pages by ids /// - Task> GetByIds(params string[] ids); + Task> GetByIds(params string[] ids); /// /// Get all available page types @@ -435,22 +435,22 @@ namespace zero.Core.Api /// /// Creates or updates a page /// - Task> Save(IPage model); + Task> Save(Page model); /// /// Update sorting of pages on a specific level /// - Task>> SaveSorting(string[] sortedIds); + Task>> SaveSorting(string[] sortedIds); /// /// Move a page to a new parent /// - Task> Move(string id, string parentId); + Task> Move(string id, string parentId); /// /// Copies a page (with optional descendants) to a new location /// - Task> Copy(string id, string destinationId, bool includeDescendants = false); + Task> Copy(string id, string destinationId, bool includeDescendants = false); /// /// Deletes a page by Id (with all it's descendants) diff --git a/zero.Core/Api/PreviewApi.cs b/zero.Core/Api/PreviewApi.cs index 8f33671d..b48a5017 100644 --- a/zero.Core/Api/PreviewApi.cs +++ b/zero.Core/Api/PreviewApi.cs @@ -8,25 +8,25 @@ namespace zero.Core.Api { public class PreviewApi : BackofficeApi, IPreviewApi { - IPreview Blueprint; + Preview Blueprint; - public PreviewApi(IBackofficeStore store, IPreview blueprint) : base(store) + public PreviewApi(IBackofficeStore store, Preview blueprint) : base(store) { Blueprint = blueprint; } /// - public async Task> Add(TEntity model) where TEntity : IZeroEntity + public async Task> Add(TEntity model) where TEntity : ZeroEntity { return await Update(null, model); } /// - public async Task> Update(string id, TEntity model) where TEntity : IZeroEntity + public async Task> Update(string id, TEntity model) where TEntity : ZeroEntity { - IPreview entity = id == null ? await GetById(id) : Blueprint.Clone(); + Preview entity = id == null ? await GetById(id) : Blueprint.Clone(); entity.Content = model; entity.OriginalId = model.Id; entity.Name = model.Name; @@ -39,16 +39,16 @@ namespace zero.Core.Api /// - public async Task GetById(string id) + public async Task GetById(string id) { - return await GetById(id); + return await GetById(id); } /// /// Get preview expiration for a document /// - DateTime GetExpiry(IZeroEntity model) + DateTime GetExpiry(ZeroEntity model) { return DateTime.Now.AddHours(1); } @@ -59,16 +59,16 @@ namespace zero.Core.Api /// /// Adds an entity to the preview collection. This will generate a preview with an id which can be used for the preview view. /// - Task> Add(TEntity model) where TEntity : IZeroEntity; + Task> Add(TEntity model) where TEntity : ZeroEntity; /// /// Updates an entity in the preview collection. This will generate a preview with an id which can be used for the preview view. /// - Task> Update(string id, TEntity model) where TEntity : IZeroEntity; + Task> Update(string id, TEntity model) where TEntity : ZeroEntity; /// /// Get preview entity by Id /// - Task GetById(string id); + Task GetById(string id); } } diff --git a/zero.Core/Api/RecycleBinApi.cs b/zero.Core/Api/RecycleBinApi.cs index 73fb42e5..90784579 100644 --- a/zero.Core/Api/RecycleBinApi.cs +++ b/zero.Core/Api/RecycleBinApi.cs @@ -11,18 +11,18 @@ namespace zero.Core.Api { public class RecycleBinApi : BackofficeApi, IRecycleBinApi { - IRecycledEntity Blueprint; + RecycledEntity Blueprint; - public RecycleBinApi(IBackofficeStore store, IRecycledEntity blueprint) : base(store) + public RecycleBinApi(IBackofficeStore store, RecycledEntity blueprint) : base(store) { Blueprint = blueprint; } /// - public async Task> Add(TEntity model, string group = null, string operationId = null) where TEntity : IZeroEntity + public async Task> Add(TEntity model, string group = null, string operationId = null) where TEntity : ZeroEntity { - IRecycledEntity entity = Blueprint.Clone(); + RecycledEntity entity = Blueprint.Clone(); entity.Group = group; entity.Content = model; entity.OriginalId = model.Id; @@ -34,42 +34,42 @@ namespace zero.Core.Api /// - public async Task>> Add(IEnumerable models, string group = null) where TEntity : IZeroEntity + public async Task>> Add(IEnumerable models, string group = null) where TEntity : ZeroEntity { - IList results = new List(); + IList results = new List(); string operationId = IdGenerator.Create(); foreach (TEntity model in models) { - EntityResult result = await Add(model, group, operationId); + EntityResult result = await Add(model, group, operationId); if (!result.IsSuccess) { - return EntityResult>.Fail(result.Errors); + return EntityResult>.Fail(result.Errors); } results.Add(result.Model); } - return EntityResult>.Success(results); + return EntityResult>.Success(results); } /// - public async Task GetById(string id) + public async Task GetById(string id) { - return await GetById(id); + return await GetById(id); } /// - public async Task> GetByQuery(RecycleBinListQuery query) + public async Task> GetByQuery(RecycleBinListQuery query) { query.SearchSelector = x => x.Name; using (IAsyncDocumentSession session = Store.OpenAsyncSession()) { - return await session.Query() + return await session.Query() .WhereIf(x => x.Group == query.Group, !query.Group.IsNullOrWhiteSpace()) .WhereIf(x => x.OperationId == query.OperationId, !query.OperationId.IsNullOrWhiteSpace()) .ToQueriedListAsync(query); @@ -78,11 +78,11 @@ namespace zero.Core.Api /// - public async Task> GetByOperation(string operationId) + public async Task> GetByOperation(string operationId) { using (IAsyncDocumentSession session = Store.OpenAsyncSession()) { - return await session.Query() + return await session.Query() .Where(x => x.OperationId == operationId) .ToListAsync(); } @@ -96,7 +96,7 @@ namespace zero.Core.Api { using (IAsyncDocumentSession session = Store.OpenAsyncSession()) { - return await session.Query() + return await session.Query() .Where(x => x.OperationId == operationId) .CountAsync(); } @@ -104,31 +104,31 @@ namespace zero.Core.Api /// - public async Task> Delete(string id) + public async Task> Delete(string id) { - return await DeleteById(id); + return await DeleteById(id); } /// - public async Task> DeleteAll() + public async Task> DeleteAll() { // TODO make Purge operations app-aware - return await Purge(); + return await Purge(); } /// - public async Task> DeleteByOperation(string operationId) + public async Task> DeleteByOperation(string operationId) { - return await Purge("where c.OperationId = $id", new Raven.Client.Parameters() { { "id", operationId } }); + return await Purge("where c.OperationId = $id", new Raven.Client.Parameters() { { "id", operationId } }); } /// - public async Task> DeleteByGroup(string group) + public async Task> DeleteByGroup(string group) { - return await Purge("where c.Group = $group", new Raven.Client.Parameters() { { "group", group } }); + return await Purge("where c.Group = $group", new Raven.Client.Parameters() { { "group", group } }); } } @@ -137,27 +137,27 @@ namespace zero.Core.Api /// /// Adds an entity to the recycle bin. This operation will not remove this entity from it's own collection! /// - Task> Add(TEntity model, string group = null, string operationId = null) where TEntity : IZeroEntity; + Task> Add(TEntity model, string group = null, string operationId = null) where TEntity : ZeroEntity; /// /// Adds the specified entities to the recycle bin. This operation will not remove entities from their own collection! /// - Task>> Add(IEnumerable models, string group = null) where TEntity : IZeroEntity; + Task>> Add(IEnumerable models, string group = null) where TEntity : ZeroEntity; /// /// Get recycled entity by Id /// - Task GetById(string id); + Task GetById(string id); /// /// Get all recycled items /// - Task> GetByQuery(RecycleBinListQuery query); + Task> GetByQuery(RecycleBinListQuery query); /// /// Get affected entities from a specific operation /// - Task> GetByOperation(string operationId); + Task> GetByOperation(string operationId); /// /// Get affected entity count from a specific operation @@ -167,21 +167,21 @@ namespace zero.Core.Api // /// Deletes a recycled entity by Id /// - Task> Delete(string id); + Task> Delete(string id); /// /// Purges the recycle bin /// - Task> DeleteAll(); + Task> DeleteAll(); /// /// Deletes all recycled items from a specific operation /// - Task> DeleteByOperation(string operationId); + Task> DeleteByOperation(string operationId); /// /// Deletes all recycled items from a specific group /// - Task> DeleteByGroup(string group); + Task> DeleteByGroup(string group); } } diff --git a/zero.Core/Api/RevisionsApi.cs b/zero.Core/Api/RevisionsApi.cs index 1ddaab3d..05bd0cc1 100644 --- a/zero.Core/Api/RevisionsApi.cs +++ b/zero.Core/Api/RevisionsApi.cs @@ -35,7 +35,7 @@ namespace zero.Core.Api /// /// Get revision list for an entity /// - public async Task> GetPaged(string id, int pageNumber = 1, int pageSize = 10, bool includeContent = false) where T : IZeroEntity + public async Task> GetPaged(string id, int pageNumber = 1, int pageSize = 10, bool includeContent = false) where T : ZeroEntity { using IAsyncDocumentSession session = Store.OpenAsyncSession(); @@ -65,7 +65,7 @@ namespace zero.Core.Api // load affected users as the revisions could have been edited by other users too string[] userIds = items.Select(x => x.LastModifiedById).Distinct().ToArray(); - Dictionary users = await UserApi.GetByIds(userIds); + Dictionary users = await UserApi.GetByIds(userIds); // create revision objects foreach (T item in items) @@ -77,7 +77,7 @@ namespace zero.Core.Api Json = includeContent ? JsonConvert.SerializeObject(item) : null }; - if (!item.LastModifiedById.IsNullOrEmpty() && users.TryGetValue(item.LastModifiedById, out IBackofficeUser user) && user != null) + if (!item.LastModifiedById.IsNullOrEmpty() && users.TryGetValue(item.LastModifiedById, out BackofficeUser user) && user != null) { revision.User = new RevisionUser() { @@ -100,6 +100,6 @@ namespace zero.Core.Api /// /// Get revision list (without content JSON) for an entity /// - Task> GetPaged(string id, int pageNumber = 1, int pageSize = 10, bool includeContent = false) where T : IZeroEntity; + Task> GetPaged(string id, int pageNumber = 1, int pageSize = 10, bool includeContent = false) where T : ZeroEntity; } } diff --git a/zero.Core/Api/SetupApi.cs b/zero.Core/Api/SetupApi.cs index ee3feac1..7b29bbbe 100644 --- a/zero.Core/Api/SetupApi.cs +++ b/zero.Core/Api/SetupApi.cs @@ -246,7 +246,7 @@ namespace zero.Core.Api Icon = "fth-award", CreatedDate = DateTimeOffset.Now, IsActive = true, - Claims = new List() + Claims = new List() { //new UserClaim(type, Permissions.Applications, PermissionsValue.Write), new UserClaim(type, Permissions.Sections.Dashboard, PermissionsValue.True), @@ -271,7 +271,7 @@ namespace zero.Core.Api Icon = "fth-feather", CreatedDate = DateTimeOffset.Now, IsActive = true, - Claims = new List() + Claims = new List() { new UserClaim(type, Permissions.Sections.Dashboard, PermissionsValue.True), new UserClaim(type, Permissions.Sections.Spaces, PermissionsValue.True), @@ -290,7 +290,7 @@ namespace zero.Core.Api Icon = "fth-users", CreatedDate = DateTimeOffset.Now, IsActive = true, - Claims = new List() + Claims = new List() { new UserClaim(type, Permissions.Sections.Dashboard, PermissionsValue.True) } @@ -300,9 +300,9 @@ namespace zero.Core.Api } - T Prepare(T model, string languageId = null) where T : IZeroIdEntity + T Prepare(T model, string languageId = null) where T : ZeroIdEntity { - IZeroEntity zeroEntity = model as IZeroEntity; + ZeroEntity zeroEntity = model as ZeroEntity; // set default properties if (zeroEntity != null && zeroEntity.CreatedDate == default) @@ -313,10 +313,9 @@ namespace zero.Core.Api { zeroEntity.CreatedById = Constants.Auth.SystemUser; } - - if (model is ILanguageAwareEntity && (model as ILanguageAwareEntity).LanguageId == null) + if (zeroEntity != null && zeroEntity.LanguageId == default) { - (model as ILanguageAwareEntity).LanguageId = languageId; + zeroEntity.LanguageId = languageId; } // update name alias and last modified diff --git a/zero.Core/Api/SpacesApi.cs b/zero.Core/Api/SpacesApi.cs index df6068d5..9dcbeb53 100644 --- a/zero.Core/Api/SpacesApi.cs +++ b/zero.Core/Api/SpacesApi.cs @@ -29,7 +29,7 @@ namespace zero.Core.Api /// - public Space GetBy() where T : ISpaceContent + public Space GetBy() where T : SpaceContent { Type type = typeof(T); return GetAll().FirstOrDefault(x => x.Type == type); @@ -44,13 +44,13 @@ namespace zero.Core.Api /// - public async Task GetItem(string alias, string id = null) + public async Task GetItem(string alias, string id = null) { Space space = GetByAlias(alias); using (IAsyncDocumentSession session = Store.OpenAsyncSession()) { - return await session.Query() + return await session.Query() .Where(x => x.SpaceAlias == space.Alias) .WhereIf(x => x.Id == id, !id.IsNullOrEmpty()) .FirstOrDefaultAsync(); @@ -59,7 +59,7 @@ namespace zero.Core.Api /// - public async Task GetItem(string id = null) where T : ISpaceContent + public async Task GetItem(string id = null) where T : SpaceContent { Space space = GetBy(); @@ -74,13 +74,13 @@ namespace zero.Core.Api /// - public async Task> GetListByQuery(string alias, ListQuery query) + public async Task> GetListByQuery(string alias, ListQuery query) { query.SearchSelector = item => item.Name; using (IAsyncDocumentSession session = Store.OpenAsyncSession()) { - return await session.Query() + return await session.Query() .Where(x => x.SpaceAlias == alias) .ToQueriedListAsync(query); } @@ -88,7 +88,7 @@ namespace zero.Core.Api /// - public async Task> GetListByQuery(string alias, ListQuery query) where T : ISpaceContent + public async Task> GetListByQuery(string alias, ListQuery query) where T : SpaceContent { query.SearchSelector = item => item.Name; @@ -102,7 +102,7 @@ namespace zero.Core.Api /// - public async Task> GetListByQuery(ListQuery query) where T : ISpaceContent + public async Task> GetListByQuery(ListQuery query) where T : SpaceContent { Space space = GetBy(); query.SearchSelector = item => item.Name; @@ -117,16 +117,16 @@ namespace zero.Core.Api /// - public async Task> Save(ISpaceContent model) + public async Task> Save(SpaceContent model) { return await SaveModel(model, null); } /// - public async Task> Delete(string id) + public async Task> Delete(string id) { - return await DeleteById(id); + return await DeleteById(id); } } @@ -141,7 +141,7 @@ namespace zero.Core.Api /// /// Returns a space by a defined generic /// - Space GetBy() where T : ISpaceContent; + Space GetBy() where T : SpaceContent; /// /// Get all spaces @@ -151,36 +151,36 @@ namespace zero.Core.Api /// /// Get editor item for a space /// - Task GetItem(string alias, string id = null); + Task GetItem(string alias, string id = null); /// /// Get editor item for a space /// - Task GetItem(string id = null) where T : ISpaceContent; + Task GetItem(string id = null) where T : SpaceContent; /// /// Get all list items for a space (with query) /// - Task> GetListByQuery(string alias, ListQuery query); + Task> GetListByQuery(string alias, ListQuery query); /// /// Get all list items for a space (with query) /// - Task> GetListByQuery(string alias, ListQuery query) where T : ISpaceContent; + Task> GetListByQuery(string alias, ListQuery query) where T : SpaceContent; /// /// Get all list items for a space (with query) /// - Task> GetListByQuery(ListQuery query) where T : ISpaceContent; + Task> GetListByQuery(ListQuery query) where T : SpaceContent; /// /// Saves a content item in a space /// - Task> Save(ISpaceContent model); + Task> Save(SpaceContent model); /// /// Deletes a space content item /// - Task> Delete(string id); + Task> Delete(string id); } } diff --git a/zero.Core/Api/Token.cs b/zero.Core/Api/Token.cs index a72299d2..210372a3 100644 --- a/zero.Core/Api/Token.cs +++ b/zero.Core/Api/Token.cs @@ -27,7 +27,7 @@ namespace zero.Core.Api /// - public bool Verify(IZeroIdEntity entity, string token) + public bool Verify(ZeroIdEntity entity, string token) { return Verify(entity?.Id, token); } @@ -54,7 +54,7 @@ namespace zero.Core.Api /// - public string Get(IZeroIdEntity entity) + public string Get(ZeroIdEntity entity) { return Get(entity?.Id); } @@ -91,7 +91,7 @@ namespace zero.Core.Api /// /// Verifies if the change token is valid for the entity /// - bool Verify(IZeroIdEntity entity, string token); + bool Verify(ZeroIdEntity entity, string token); /// /// Verifies if the change token is valid for the entity @@ -101,7 +101,7 @@ namespace zero.Core.Api /// /// Get a new change token for the entity /// - string Get(IZeroIdEntity entity); + string Get(ZeroIdEntity entity); /// /// Get a new change token for the entity diff --git a/zero.Core/Api/UserApi.cs b/zero.Core/Api/UserApi.cs index 8eb59bb1..e50592e1 100644 --- a/zero.Core/Api/UserApi.cs +++ b/zero.Core/Api/UserApi.cs @@ -24,83 +24,83 @@ namespace zero.Core.Api /// - public async Task GetUserById(string id) + public async Task GetUserById(string id) { - IBackofficeUser user = await UserManager.FindByIdAsync(id); + BackofficeUser user = await UserManager.FindByIdAsync(id); return user; } /// - public async Task GetUserByEmail(string email) + public async Task GetUserByEmail(string email) { - IBackofficeUser user = await UserManager.FindByEmailAsync(email); + BackofficeUser user = await UserManager.FindByEmailAsync(email); return user; } /// - public async Task> GetByIds(params string[] ids) + public async Task> GetByIds(params string[] ids) { - return await GetByIds(ids); + return await GetByIds(ids); } /// - public async Task> GetAll() + public async Task> GetAll() { using IAsyncDocumentSession session = Session(); - return await session.Query() + return await session.Query() .OrderByDescending(x => x.CreatedDate) .ToListAsync(); } /// - public async Task> GetByQuery(ListQuery query) + public async Task> GetByQuery(ListQuery query) { string currentUserId = UserManager.GetUserId(Context.BackofficeUser); query.SearchSelector = user => user.Name; using IAsyncDocumentSession session = Session(); - return await session.Query() + return await session.Query() .ToQueriedListAsync(query); } /// - public async Task> Save(IBackofficeUser model) + public async Task> Save(BackofficeUser model) { return await SaveModel(model); //, new UserValidator()); } /// - public async Task> Delete(string id) + public async Task> Delete(string id) { - return await DeleteById(id); + return await DeleteById(id); } /// - public async Task> UpdatePassword(IBackofficeUser user, string currentPassword, string newPassword) + public async Task> UpdatePassword(BackofficeUser user, string currentPassword, string newPassword) { if (currentPassword.IsNullOrWhiteSpace() || newPassword.IsNullOrWhiteSpace()) { - return EntityResult.Fail(nameof(currentPassword), "@errors.changepassword.emptyfields"); + return EntityResult.Fail(nameof(currentPassword), "@errors.changepassword.emptyfields"); } if (user == null) { - return EntityResult.Fail("@errors.changepassword.nouser"); + return EntityResult.Fail("@errors.changepassword.nouser"); } IdentityResult identityResult = await UserManager.ChangePasswordAsync(user as BackofficeUser, currentPassword, newPassword); if (!identityResult.Succeeded) { - EntityResult result = EntityResult.Fail(); + EntityResult result = EntityResult.Fail(); foreach (IdentityError error in identityResult.Errors) { @@ -110,19 +110,19 @@ namespace zero.Core.Api return result; } - return EntityResult.Success(user); + return EntityResult.Success(user); } /// - public async Task> Enable(IBackofficeUser user) + public async Task> Enable(BackofficeUser user) { return await UpdateActiveState(user, true); } /// - public async Task> Disable(IBackofficeUser user) + public async Task> Disable(BackofficeUser user) { return await UpdateActiveState(user, false); } @@ -132,7 +132,7 @@ namespace zero.Core.Api /// Updates the active state of user. /// If IsActive=false, the user cannot login anymore /// - async Task> UpdateActiveState(IBackofficeUser user, bool isActive) + async Task> UpdateActiveState(BackofficeUser user, bool isActive) { user.IsActive = isActive; @@ -140,7 +140,7 @@ namespace zero.Core.Api if (!identityResult.Succeeded) { - EntityResult result = EntityResult.Fail(); + EntityResult result = EntityResult.Fail(); foreach (IdentityError error in identityResult.Errors) { @@ -152,7 +152,7 @@ namespace zero.Core.Api await UserManager.UpdateSecurityStampAsync(user as BackofficeUser); - return EntityResult.Success(user); + return EntityResult.Success(user); } } @@ -162,52 +162,52 @@ namespace zero.Core.Api /// /// Find user by id /// - Task GetUserById(string id); + Task GetUserById(string id); /// /// Find user by email /// - Task GetUserByEmail(string email); + Task GetUserByEmail(string email); /// /// Get users by ids /// - Task> GetByIds(params string[] ids); + Task> GetByIds(params string[] ids); /// /// Get all users for the selected application /// - Task> GetAll(); + Task> GetAll(); /// /// Get all available users (with query) /// - Task> GetByQuery(ListQuery query); + Task> GetByQuery(ListQuery query); /// /// Creates or updates a user /// - Task> Save(IBackofficeUser model); + Task> Save(BackofficeUser model); /// /// Deletes a user /// - Task> Delete(string id); + Task> Delete(string id); /// /// Changes the password of the current user. /// User is logged out if this operation succeeds. /// - Task> UpdatePassword(IBackofficeUser user, string currentPassword, string newPassword); + Task> UpdatePassword(BackofficeUser user, string currentPassword, string newPassword); /// /// Enables a user /// - Task> Enable(IBackofficeUser user); + Task> Enable(BackofficeUser user); /// /// Disables a user /// - Task> Disable(IBackofficeUser user); + Task> Disable(BackofficeUser user); } } diff --git a/zero.Core/Api/UserRolesApi.cs b/zero.Core/Api/UserRolesApi.cs index d4b6717e..56d2afce 100644 --- a/zero.Core/Api/UserRolesApi.cs +++ b/zero.Core/Api/UserRolesApi.cs @@ -35,28 +35,28 @@ namespace zero.Core.Api /// - public async Task> GetAll() + public async Task> GetAll() { using IAsyncDocumentSession session = Session(); - return await session.Query().OrderBy(x => x.Sort).ThenBy(x => x.Name).ToListAsync(); + return await session.Query().OrderBy(x => x.Sort).ThenBy(x => x.Name).ToListAsync(); } /// - public async Task GetById(string id) + public async Task GetById(string id) { return await RoleManager.FindByIdAsync(id); } /// - public async Task> Save(IBackofficeUserRole model) + public async Task> Save(BackofficeUserRole model) { ValidationResult validation = await new UserRoleValidator().ValidateAsync(model); if (!validation.IsValid) { - return EntityResult.Fail(validation); + return EntityResult.Fail(validation); } if (model.Id.IsNullOrEmpty()) @@ -80,12 +80,12 @@ namespace zero.Core.Api } } - return EntityResult.Success(model); + return EntityResult.Success(model); } /// - public async Task> Delete(string id) + public async Task> Delete(string id) { using (IAsyncDocumentSession session = Session()) { @@ -93,7 +93,7 @@ namespace zero.Core.Api if (country == null) { - return EntityResult.Fail("@errors.ondelete.idnotfound"); + return EntityResult.Fail("@errors.ondelete.idnotfound"); } session.Delete(country); @@ -101,7 +101,7 @@ namespace zero.Core.Api await session.SaveChangesAsync(); } - return EntityResult.Success(); + return EntityResult.Success(); } } @@ -111,21 +111,21 @@ namespace zero.Core.Api /// /// Get all user roles /// - Task> GetAll(); + Task> GetAll(); /// /// Get role by id /// - Task GetById(string id); + Task GetById(string id); /// /// Create or update a role /// - Task> Save(IBackofficeUserRole model); + Task> Save(BackofficeUserRole model); /// /// Deletes a role /// - Task> Delete(string id); + Task> Delete(string id); } } diff --git a/zero.Core/ApplicationResolver.cs b/zero.Core/ApplicationResolver.cs index fc78f1b0..76989417 100644 --- a/zero.Core/ApplicationResolver.cs +++ b/zero.Core/ApplicationResolver.cs @@ -28,7 +28,7 @@ namespace zero.Core protected IHandlerHolder Handler { get; private set; } - private IList Apps { get; set; } + private IList Apps { get; set; } @@ -42,7 +42,7 @@ namespace zero.Core /// - public async Task Resolve(HttpContext context, ClaimsPrincipal user) + public async Task Resolve(HttpContext context, ClaimsPrincipal user) { if (context?.Request == null) { @@ -50,7 +50,7 @@ namespace zero.Core return null; } - IApplication app; + Application app; if (context.IsBackofficeRequest(Options.BackofficePath)) { @@ -64,7 +64,7 @@ namespace zero.Core if (app == null) { //Logger.LogWarning("Could not resolve application for host {host}", context.Request.Host); - IList apps = await GetApplications(); + IList apps = await GetApplications(); app = apps.FirstOrDefault(); } @@ -73,15 +73,15 @@ namespace zero.Core /// - public async Task ResolveFromUser(ClaimsPrincipal user) + public async Task ResolveFromUser(ClaimsPrincipal user) { - IBackofficeUser userEntity = await GetBackofficeUser(user); + BackofficeUser userEntity = await GetBackofficeUser(user); return await ResolveFromUser(userEntity); } /// - public async Task ResolveFromUser(IBackofficeUser user) + public async Task ResolveFromUser(BackofficeUser user) { if (user == null) { @@ -113,26 +113,26 @@ namespace zero.Core } using IAsyncDocumentSession session = Store.OpenCoreSession(); - return await session.LoadAsync(appId); + return await session.LoadAsync(appId); } /// - public async Task ResolveFromRequest(HttpContext context) + public async Task ResolveFromRequest(HttpContext context) { return Handler.Get()?.Resolve(context.Request, await GetApplications()) ?? await ResolveFromUri(context.Request.GetEncodedUrl()); } /// - public async Task ResolveFromUri(string uriString) + public async Task ResolveFromUri(string uriString) { return ResolveFromUriInternal(new Uri(uriString, UriKind.Absolute), await GetApplications()); } /// - public async Task ResolveFromUri(Uri uri) + public async Task ResolveFromUri(Uri uri) { return ResolveFromUriInternal(uri, await GetApplications()); } @@ -141,9 +141,9 @@ namespace zero.Core /// /// Get matching application from an URI /// - IApplication ResolveFromUriInternal(Uri uri, IList apps) + Application ResolveFromUriInternal(Uri uri, IList apps) { - foreach (IApplication app in apps) + foreach (Application app in apps) { if (app.Domains?.Length < 1) { @@ -168,7 +168,7 @@ namespace zero.Core /// /// Get all applications to choose from /// - async Task> GetApplications() + async Task> GetApplications() { if (Apps != null) { @@ -176,7 +176,7 @@ namespace zero.Core } using IAsyncDocumentSession session = Store.OpenCoreSession(); - Apps = await session.Query().ToListAsync(); + Apps = await session.Query().ToListAsync(); return Apps; } @@ -184,12 +184,12 @@ namespace zero.Core /// /// Get backoffice user from claims principal /// - async Task GetBackofficeUser(ClaimsPrincipal user) + async Task GetBackofficeUser(ClaimsPrincipal user) { string userId = user.FindFirstValue(Constants.Auth.Claims.UserId); using IAsyncDocumentSession session = Store.OpenCoreSession(); - return await session.LoadAsync(userId); + return await session.LoadAsync(userId); } } @@ -200,33 +200,33 @@ namespace zero.Core /// Resolves the current application from either the backoffice user (in case it is backoffice request) /// or the domain (in case it is frontend request). /// - Task Resolve(HttpContext context, ClaimsPrincipal user); + Task Resolve(HttpContext context, ClaimsPrincipal user); /// /// Resolves the current application from the request path /// - Task ResolveFromRequest(HttpContext context); + Task ResolveFromRequest(HttpContext context); /// /// Get matching application from an URI string /// - Task ResolveFromUri(string uriString); + Task ResolveFromUri(string uriString); /// /// Get matching application from an URI /// - Task ResolveFromUri(Uri uri); + Task ResolveFromUri(Uri uri); /// /// Resolves the current application from the logged-in backoffice user. /// This method won't return apps the user has no access to. /// - Task ResolveFromUser(ClaimsPrincipal user); + Task ResolveFromUser(ClaimsPrincipal user); /// /// Resolves the current application from a user. /// This method won't return apps the user has no access to. /// - Task ResolveFromUser(IBackofficeUser user); + Task ResolveFromUser(BackofficeUser user); } } diff --git a/zero.Core/Collections/CollectionBase.cs b/zero.Core/Collections/CollectionBase.cs index d5babe07..80d65e0e 100644 --- a/zero.Core/Collections/CollectionBase.cs +++ b/zero.Core/Collections/CollectionBase.cs @@ -17,7 +17,7 @@ using zero.Core.Utils; namespace zero.Core.Collections { - public abstract class CollectionBase : ICollectionBase, IDisposable where T : IZeroEntity + public abstract class CollectionBase : ICollectionBase, IDisposable where T : ZeroEntity { private IAsyncDocumentSession _session; private string _database; @@ -216,11 +216,7 @@ namespace zero.Core.Collections model.CreatedDate = DateTimeOffset.Now; model.CreatedById = userId; - - if (model is ILanguageAwareEntity) - { - (model as ILanguageAwareEntity).LanguageId = "languages.1-A"; // TODO correct language id - } + model.LanguageId = "languages.1-A"; // TODO correct language id } // update name alias and last modified @@ -425,7 +421,7 @@ namespace zero.Core.Collections } - public interface ICollectionBase : IDisposable where T : IZeroEntity + public interface ICollectionBase : IDisposable where T : ZeroEntity { /// /// Guid for this instance diff --git a/zero.Core/Collections/CollectionConfigBase.cs b/zero.Core/Collections/CollectionConfigBase.cs deleted file mode 100644 index 0dc8d631..00000000 --- a/zero.Core/Collections/CollectionConfigBase.cs +++ /dev/null @@ -1,103 +0,0 @@ -using FluentValidation; -using Raven.Client.Documents; -using Raven.Client.Documents.Linq; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using zero.Core.Entities; -using zero.Core.Extensions; -using zero.Core.Options; - -namespace zero.Core.Collections -{ - public abstract class CollectionConfigBase : CollectionBase, IFixedCollectionBase, IDisposable where T : IZeroConfigEntity - { - public CollectionConfigBase(IZeroContext context, ICollectionInterceptorHandler interceptorHandler = null, IValidator validator = null) : base(context, interceptorHandler, validator) { } - - - protected abstract IEnumerable GetDefinedTypes(); - - - /// - public virtual async Task GetByType() where TSpecific : T, new() - { - OptionsType type = GetDefinedTypes().FirstOrDefault(x => x.ContentType == typeof(TSpecific)); - return await GetEntity(type); - } - - - /// - public virtual async Task GetByType(string alias) where TSpecific : T, new() - { - OptionsType type = GetDefinedTypes().FirstOrDefault(x => x.ContentType == typeof(TSpecific) && x.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase)); - return await GetEntity(type); - } - - - /// - public virtual async Task GetByAlias(string alias) - { - OptionsType type = GetDefinedTypes().FirstOrDefault(x => x.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase)); - return type != null ? await Session.Query().FirstOrDefaultAsync(x => x.TypeAlias == type.Alias) : default; - } - - - ///// - //public override async Task> GetByQuery(ListQuery query) - //{ - // ListResult list = await Session.Query().OrderByDescending(x => x.CreatedDate).ToQueriedListAsync(query); - //} - - - /// - /// Get data from database - /// - async Task GetEntity(OptionsType type) where TSpecific : T, new() - { - if (type == null) - { - return default; - } - - TSpecific model = await Session.Query().FirstOrDefaultAsync(x => x.TypeAlias == type.Alias); - - if (model == null) //&& type.IsAutoActivated) - { - return new TSpecific(); - } - - return model; - } - } - - - public interface IFixedCollectionBase : IDisposable where T : IZeroEntity - { - /// - /// Guid for this instance - /// - Guid Guid { get; } - - /// - /// The database to operate on. - /// Is null by default, which uses the database from the resolved application. - /// - string Database { get; set; } - - /// - /// Returns a new document queryable - /// - IRavenQueryable Query { get; } - - /// - /// Applies the scope to the service instance - /// - void ApplyScope(string scope); - - /// - /// Get an entity by alias - /// - //Task GetByAlias(string alias); - } -} diff --git a/zero.Core/Collections/CollectionInterceptor.cs b/zero.Core/Collections/CollectionInterceptor.cs index 2e07a824..7c9d25cc 100644 --- a/zero.Core/Collections/CollectionInterceptor.cs +++ b/zero.Core/Collections/CollectionInterceptor.cs @@ -2,8 +2,6 @@ using Raven.Client.Documents.Session; using System; using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; using System.Threading.Tasks; using zero.Core.Database; using zero.Core.Entities; @@ -16,31 +14,31 @@ namespace zero.Core.Collections public virtual HashSet Types { get; } = new(); /// - public virtual Task> Creating(CreateParameters args) where T : IZeroEntity => Task.FromResult>(default); + public virtual Task> Creating(CreateParameters args) where T : ZeroEntity => Task.FromResult>(default); /// - public virtual Task> Updating(UpdateParameters args) where T : IZeroEntity => Task.FromResult>(default); + public virtual Task> Updating(UpdateParameters args) where T : ZeroEntity => Task.FromResult>(default); /// - public virtual Task> Deleting(DeleteParameters args) where T : IZeroEntity => Task.FromResult>(default); + public virtual Task> Deleting(DeleteParameters args) where T : ZeroEntity => Task.FromResult>(default); /// - public virtual Task> Purging(PurgeParameters args) where T : IZeroEntity => Task.FromResult>(default); + public virtual Task> Purging(PurgeParameters args) where T : ZeroEntity => Task.FromResult>(default); /// - public virtual Task Created(CreateParameters args) where T : IZeroEntity => Task.CompletedTask; + public virtual Task Created(CreateParameters args) where T : ZeroEntity => Task.CompletedTask; /// - public virtual Task Updated(UpdateParameters args) where T : IZeroEntity => Task.CompletedTask; + public virtual Task Updated(UpdateParameters args) where T : ZeroEntity => Task.CompletedTask; /// - public virtual Task Deleted(DeleteParameters args) where T : IZeroEntity => Task.CompletedTask; + public virtual Task Deleted(DeleteParameters args) where T : ZeroEntity => Task.CompletedTask; /// - public virtual Task Purged(PurgeParameters args) where T : IZeroEntity => Task.CompletedTask; + public virtual Task Purged(PurgeParameters args) where T : ZeroEntity => Task.CompletedTask; - public class Parameters where T : IZeroEntity + public class Parameters where T : ZeroEntity { /// /// The current zero context @@ -63,7 +61,7 @@ namespace zero.Core.Collections public IValidator Validator { get; set; } } - public class CreateParameters : Parameters where T : IZeroEntity + public class CreateParameters : Parameters where T : ZeroEntity { /// /// The model which is created @@ -71,7 +69,7 @@ namespace zero.Core.Collections public T Model { get; set; } } - public class UpdateParameters : Parameters where T : IZeroEntity + public class UpdateParameters : Parameters where T : ZeroEntity { /// /// The Id of the model which is updated @@ -84,7 +82,7 @@ namespace zero.Core.Collections public T Model { get; set; } } - public class DeleteParameters : Parameters where T : IZeroEntity + public class DeleteParameters : Parameters where T : ZeroEntity { /// /// The id of the model which is deleted @@ -97,7 +95,7 @@ namespace zero.Core.Collections public T Model { get; set; } } - public class PurgeParameters : Parameters where T : IZeroEntity { } + public class PurgeParameters : Parameters where T : ZeroEntity { } } @@ -111,41 +109,41 @@ namespace zero.Core.Collections /// /// Called after an entity has been stored but before the session has saved its changes /// - Task Created(CollectionInterceptor.CreateParameters args) where T : IZeroEntity; + Task Created(CollectionInterceptor.CreateParameters args) where T : ZeroEntity; /// /// Called before an entity is stored and validated /// - Task> Creating(CollectionInterceptor.CreateParameters args) where T : IZeroEntity; + Task> Creating(CollectionInterceptor.CreateParameters args) where T : ZeroEntity; /// /// Called after an entity has been deleted but before the session has saved its changes /// - Task Deleted(CollectionInterceptor.DeleteParameters args) where T : IZeroEntity; + Task Deleted(CollectionInterceptor.DeleteParameters args) where T : ZeroEntity; /// /// Called before an entity is deleted /// - Task> Deleting(CollectionInterceptor.DeleteParameters args) where T : IZeroEntity; + Task> Deleting(CollectionInterceptor.DeleteParameters args) where T : ZeroEntity; /// /// Called after the document collection has been purged /// - Task Purged(CollectionInterceptor.PurgeParameters args) where T : IZeroEntity; + Task Purged(CollectionInterceptor.PurgeParameters args) where T : ZeroEntity; /// /// Called before a collection is purged /// - Task> Purging(CollectionInterceptor.PurgeParameters args) where T : IZeroEntity; + Task> Purging(CollectionInterceptor.PurgeParameters args) where T : ZeroEntity; /// /// Called after an entity has been updated but before the session has saved its changes /// - Task Updated(CollectionInterceptor.UpdateParameters args) where T : IZeroEntity; + Task Updated(CollectionInterceptor.UpdateParameters args) where T : ZeroEntity; /// /// Called before an entity is stored and validated /// - Task> Updating(CollectionInterceptor.UpdateParameters args) where T : IZeroEntity; + Task> Updating(CollectionInterceptor.UpdateParameters args) where T : ZeroEntity; } } diff --git a/zero.Core/Collections/CollectionStaticBase.cs b/zero.Core/Collections/CollectionStaticBase.cs index 0bc5c0e0..ca07d65e 100644 --- a/zero.Core/Collections/CollectionStaticBase.cs +++ b/zero.Core/Collections/CollectionStaticBase.cs @@ -120,7 +120,7 @@ // } -// public interface IICollectionPredefinedBase : IDisposable where T : IZeroEntity +// public interface IICollectionPredefinedBase : IDisposable where T : ZeroEntity // { // /// // /// Guid for this instance diff --git a/zero.Core/Collections/Countries/CountriesCollection.cs b/zero.Core/Collections/Countries/CountriesCollection.cs index 5f093c9f..7b6f9b38 100644 --- a/zero.Core/Collections/Countries/CountriesCollection.cs +++ b/zero.Core/Collections/Countries/CountriesCollection.cs @@ -7,20 +7,20 @@ using zero.Core.Extensions; namespace zero.Core.Collections { - public class CountriesCollection : CollectionBase, ICountriesCollection + public class CountriesCollection : CollectionBase, ICountriesCollection { - public CountriesCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator) : base(context, interceptor, validator) { } + public CountriesCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator) : base(context, interceptor, validator) { } /// - public override IAsyncEnumerable Stream() + public override IAsyncEnumerable Stream() { return base.Stream(q => q.OrderByDescending(x => x.IsPreferred).ThenBy(x => x.Name)); } } - public interface ICountriesCollection : ICollectionBase + public interface ICountriesCollection : ICollectionBase { } diff --git a/zero.Core/Collections/Countries/CountryValidator.cs b/zero.Core/Collections/Countries/CountryValidator.cs index e4f50650..5f9cffab 100644 --- a/zero.Core/Collections/Countries/CountryValidator.cs +++ b/zero.Core/Collections/Countries/CountryValidator.cs @@ -6,7 +6,7 @@ using zero.Core.Validation; namespace zero.Core.Collections { - public class CountryValidator : ZeroValidator + public class CountryValidator : ZeroValidator { public CountryValidator(IBackofficeStore store) { diff --git a/zero.Core/Collections/Integrations/IntegrationsCollection.cs b/zero.Core/Collections/Integrations/IntegrationsCollection.cs index 9e8d8961..194e8a30 100644 --- a/zero.Core/Collections/Integrations/IntegrationsCollection.cs +++ b/zero.Core/Collections/Integrations/IntegrationsCollection.cs @@ -12,7 +12,7 @@ using zero.Core.Options; namespace zero.Core.Collections { - public class IntegrationsCollection : CollectionBase, IIntegrationsCollection + public class IntegrationsCollection : CollectionBase, IIntegrationsCollection { /// public IReadOnlyCollection RegisteredTypes { get; private set; } @@ -31,7 +31,7 @@ namespace zero.Core.Collections /// - public IIntegration GetEmpty(string alias) + public Integration GetEmpty(string alias) { IntegrationType type = RegisteredTypes.FirstOrDefault(x => x.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase)); @@ -42,7 +42,7 @@ namespace zero.Core.Collections try { - IIntegration model = Activator.CreateInstance(type.ContentType) as IIntegration; + Integration model = Activator.CreateInstance(type.ContentType) as Integration; model.TypeAlias = type.Alias; return model; } @@ -56,7 +56,7 @@ namespace zero.Core.Collections /// - public async Task GetByAlias(string alias) + public async Task GetByAlias(string alias) { IntegrationType type = RegisteredTypes.FirstOrDefault(x => x.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase)); return await Load(type); @@ -64,7 +64,7 @@ namespace zero.Core.Collections /// - public async Task Get(string alias = null) where T : IIntegration, new() + public async Task Get(string alias = null) where T : Integration, new() { IntegrationType type = RegisteredTypes.FirstOrDefault(x => x.ContentType == typeof(T) && (alias.IsNullOrEmpty() || x.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase))); return await Load(type); @@ -72,17 +72,17 @@ namespace zero.Core.Collections /// - public async Task> GetByTag(string tag) + public async Task> GetByTag(string tag) { IEnumerable types = RegisteredTypes.Where(x => x.Tags.Contains(tag, StringComparer.InvariantCultureIgnoreCase)); if (!types.Any()) { - return new List(); + return new List(); } string[] aliases = types.Select(x => x.Alias).ToArray(); - return await Session.Query().Where(x => x.TypeAlias.In(aliases)).ToListAsync(); + return await Session.Query().Where(x => x.TypeAlias.In(aliases)).ToListAsync(); } @@ -94,14 +94,14 @@ namespace zero.Core.Collections /// - public override async Task> GetByQuery(ListQuery query) + public override async Task> GetByQuery(ListQuery query) { - List result = new(); - List models = await Session.Query().ToListAsync(); + List result = new(); + List models = await Session.Query().ToListAsync(); foreach (IntegrationType type in RegisteredTypes) { - IIntegration model = models.FirstOrDefault(x => x.TypeAlias == type.Alias); + Integration model = models.FirstOrDefault(x => x.TypeAlias == type.Alias); if (model != null) { @@ -118,11 +118,11 @@ namespace zero.Core.Collections public async Task> GetTypesWithStatus() { List result = new(); - List models = await Session.Query().ToListAsync(); + List models = await Session.Query().ToListAsync(); foreach (IntegrationType type in RegisteredTypes) { - IIntegration model = models.FirstOrDefault(x => x.TypeAlias == type.Alias); + Integration model = models.FirstOrDefault(x => x.TypeAlias == type.Alias); result.Add(new() { @@ -138,31 +138,31 @@ namespace zero.Core.Collections /// - public override async Task> Save(IIntegration model) + public override async Task> Save(Integration model) { if (model == null) { - return EntityResult.Fail("@integration.errors.notfound"); + return EntityResult.Fail("@integration.errors.notfound"); } IntegrationType type = RegisteredTypes.FirstOrDefault(x => x.Alias.Equals(model.TypeAlias, StringComparison.InvariantCultureIgnoreCase)); if (type == null) { - return EntityResult.Fail("@integration.errors.typenotfound"); + return EntityResult.Fail("@integration.errors.typenotfound"); } - string existingId = await Session.Query().Where(x => x.TypeAlias == type.Alias).Select(x => x.Id).FirstOrDefaultAsync(); + string existingId = await Session.Query().Where(x => x.TypeAlias == type.Alias).Select(x => x.Id).FirstOrDefaultAsync(); if (!existingId.IsNullOrEmpty() && existingId != model.Id) { - return EntityResult.Fail("@integration.errors.multiplenotallowed"); + return EntityResult.Fail("@integration.errors.multiplenotallowed"); } model.Alias = type.Alias; model.Name = null; - EntityResult result = await base.Save(model); + EntityResult result = await base.Save(model); if (result.IsSuccess) { @@ -174,9 +174,9 @@ namespace zero.Core.Collections /// - public async Task> Activate(string alias) + public async Task> Activate(string alias) { - IIntegration model = await GetByAlias(alias); + Integration model = await GetByAlias(alias); if (model != null) { model.IsActive = true; @@ -186,9 +186,9 @@ namespace zero.Core.Collections /// - public async Task> Deactivate(string alias) + public async Task> Deactivate(string alias) { - IIntegration model = await GetByAlias(alias); + Integration model = await GetByAlias(alias); if (model != null) { model.IsActive = false; @@ -198,7 +198,7 @@ namespace zero.Core.Collections /// - public async Task> Delete(string alias) + public async Task> Delete(string alias) { return await base.Delete(await GetByAlias(alias)); } @@ -207,7 +207,7 @@ namespace zero.Core.Collections /// /// Get integration data from database /// - protected async Task Load(IntegrationType type) where T : IIntegration, new() + protected async Task Load(IntegrationType type) where T : Integration, new() { if (type == null) { @@ -242,22 +242,22 @@ namespace zero.Core.Collections /// /// Get new integration model for the specified integration type alias /// - IIntegration GetEmpty(string alias); + Integration GetEmpty(string alias); /// /// Get integration by an alias /// - Task GetByAlias(string alias); + Task GetByAlias(string alias); /// /// Get an integration by type and optional alias /// - Task Get(string alias = null) where T : IIntegration, new(); + Task Get(string alias = null) where T : Integration, new(); /// /// Get all integrations by a certain tag /// - Task> GetByTag(string tag); + Task> GetByTag(string tag); /// /// Check if any integrations of certain tag are activated @@ -267,7 +267,7 @@ namespace zero.Core.Collections /// /// Get all integrations with the specified query /// - Task> GetByQuery(ListQuery query); + Task> GetByQuery(ListQuery query); /// /// Get all integration types with their configuration status @@ -277,21 +277,21 @@ namespace zero.Core.Collections /// /// Saves an integration /// - Task> Save(IIntegration model); + Task> Save(Integration model); /// /// Activates a configured integration /// - Task> Activate(string alias); + Task> Activate(string alias); /// /// Disables a configured integration /// - Task> Deactivate(string alias); + Task> Deactivate(string alias); /// /// Deletes configuration of an integration and disables it /// - Task> Delete(string alias); + Task> Delete(string alias); } } diff --git a/zero.Core/Collections/Languages/LanguageValidator.cs b/zero.Core/Collections/Languages/LanguageValidator.cs index e7f6d215..eb941c2b 100644 --- a/zero.Core/Collections/Languages/LanguageValidator.cs +++ b/zero.Core/Collections/Languages/LanguageValidator.cs @@ -7,7 +7,7 @@ using zero.Core.Validation; namespace zero.Core.Collections { - public class LanguageValidator : ZeroValidator + public class LanguageValidator : ZeroValidator { public LanguageValidator(IBackofficeStore store) { diff --git a/zero.Core/Collections/Languages/LanguagesCollection.cs b/zero.Core/Collections/Languages/LanguagesCollection.cs index 591612e1..2b550842 100644 --- a/zero.Core/Collections/Languages/LanguagesCollection.cs +++ b/zero.Core/Collections/Languages/LanguagesCollection.cs @@ -10,13 +10,13 @@ using zero.Core.Extensions; namespace zero.Core.Collections { - public class LanguagesCollection : CollectionBase, ILanguagesCollection + public class LanguagesCollection : CollectionBase, ILanguagesCollection { - public LanguagesCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator) : base(context, interceptor, validator) { } + public LanguagesCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator) : base(context, interceptor, validator) { } /// - public override IAsyncEnumerable Stream() + public override IAsyncEnumerable Stream() { return base.Stream(q => q.OrderByDescending(x => x.CreatedDate)); } @@ -40,7 +40,7 @@ namespace zero.Core.Collections } - public interface ILanguagesCollection : ICollectionBase + public interface ILanguagesCollection : ICollectionBase { /// /// Get all available cultures diff --git a/zero.Core/Collections/MailTemplates/MailTemplateValidator.cs b/zero.Core/Collections/MailTemplates/MailTemplateValidator.cs index 6a641afa..6c54d77f 100644 --- a/zero.Core/Collections/MailTemplates/MailTemplateValidator.cs +++ b/zero.Core/Collections/MailTemplates/MailTemplateValidator.cs @@ -3,7 +3,7 @@ using zero.Core.Validation; namespace zero.Core.Collections { - public class MailTemplateValidator : ZeroValidator + public class MailTemplateValidator : ZeroValidator { public MailTemplateValidator() { diff --git a/zero.Core/Collections/MailTemplates/MailTemplatesCollection.cs b/zero.Core/Collections/MailTemplates/MailTemplatesCollection.cs index d02f415e..39fb20f5 100644 --- a/zero.Core/Collections/MailTemplates/MailTemplatesCollection.cs +++ b/zero.Core/Collections/MailTemplates/MailTemplatesCollection.cs @@ -5,24 +5,24 @@ using zero.Core.Entities; namespace zero.Core.Collections { - public class MailTemplatesCollection : CollectionBase, IMailTemplatesCollection + public class MailTemplatesCollection : CollectionBase, IMailTemplatesCollection { - public MailTemplatesCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator) : base(context, interceptor, validator) { } + public MailTemplatesCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator) : base(context, interceptor, validator) { } /// - public async Task GetByKey(string key) + public async Task GetByKey(string key) { return await Query.FirstOrDefaultAsync(x => x.Key == key); } } - public interface IMailTemplatesCollection : ICollectionBase + public interface IMailTemplatesCollection : ICollectionBase { /// /// Get mail template by associated key /// - Task GetByKey(string key); + Task GetByKey(string key); } } diff --git a/zero.Core/Collections/Media/MediaCollection.cs b/zero.Core/Collections/Media/MediaCollection.cs index fc8c97ba..3a0ba216 100644 --- a/zero.Core/Collections/Media/MediaCollection.cs +++ b/zero.Core/Collections/Media/MediaCollection.cs @@ -19,12 +19,12 @@ using zero.Core.Extensions; namespace zero.Core.Collections { - public class MediaCollection : CollectionBase, IMediaCollection + public class MediaCollection : CollectionBase, IMediaCollection { private IAsyncDocumentSession _coreSession; - public MediaCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator, IPaths paths) : base(context, interceptor, validator) + public MediaCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator, IPaths paths) : base(context, interceptor, validator) { PreSave = model => model.IsActive = true; Paths = paths; @@ -62,36 +62,36 @@ namespace zero.Core.Collections protected IPaths Paths { get; set; } - public override Task GetById(string id) + public override Task GetById(string id) { ApplyScopeBasedOnId(id); return base.GetById(id); } - public override async Task> GetByIds(params string[] ids) + public override async Task> GetByIds(params string[] ids) { string[] localIds = ids.Where(x => !x.StartsWith(Constants.Database.CoreIdPrefix)).ToArray(); string[] coreIds = ids.Except(localIds).ToArray(); - Dictionary result = new Dictionary(); - Dictionary models = null; + Dictionary result = new Dictionary(); + Dictionary models = null; if (localIds.Length > 0) { - models = await Session.LoadAsync(localIds); + models = await Session.LoadAsync(localIds); foreach (string id in localIds) { - models.TryGetValue(id, out IMedia model); + models.TryGetValue(id, out Media model); result.Add(id, model); } } if (coreIds.Length > 0) { - models = await CoreSession.LoadAsync(coreIds); + models = await CoreSession.LoadAsync(coreIds); foreach (string id in coreIds) { - models.TryGetValue(id, out IMedia model); + models.TryGetValue(id, out Media model); result.Add(id, model); } } @@ -105,7 +105,7 @@ namespace zero.Core.Collections { ApplyScopeBasedOnId(id); - IMedia media = await Session.LoadAsync(id); + Media media = await Session.LoadAsync(id); if (media == null) { @@ -122,7 +122,7 @@ namespace zero.Core.Collections /// - public async Task> GetByQuery(MediaListQuery query) + public async Task> GetByQuery(MediaListQuery query) { ApplyScopeBasedOnId(query.FolderId); @@ -135,14 +135,14 @@ namespace zero.Core.Collections /// - public async Task> Move(string id, string parentId) + public async Task> Move(string id, string parentId) { - IMedia model = await GetById(id); - IMediaFolder parent = await Session.LoadAsync(parentId); + Media model = await GetById(id); + MediaFolder parent = await Session.LoadAsync(parentId); if (model == null || (!parentId.IsNullOrEmpty() && parent == null)) { - return EntityResult.Fail("@errors.idnotfound"); + return EntityResult.Fail("@errors.idnotfound"); } model.FolderId = parent?.Id; @@ -261,7 +261,7 @@ namespace zero.Core.Collections /// /// Saves a thumbnail of an image /// - string SaveThumbnail(IMedia media, Image image, string extensionPrefix, ResizeOptions resizeOptions) + string SaveThumbnail(Media media, Image image, string extensionPrefix, ResizeOptions resizeOptions) { string extension = Path.GetExtension(media.Source); @@ -294,7 +294,7 @@ namespace zero.Core.Collections } - public interface IMediaCollection : ICollectionBase + public interface IMediaCollection : ICollectionBase { /// /// Get media source by Id @@ -304,7 +304,7 @@ namespace zero.Core.Collections /// /// Get all available media items with query /// - Task> GetByQuery(MediaListQuery query); + Task> GetByQuery(MediaListQuery query); /// /// Get all available media items (including folders) with query @@ -314,7 +314,7 @@ namespace zero.Core.Collections /// /// Move a file to a new parent /// - Task> Move(string id, string parentId); + Task> Move(string id, string parentId); /// /// Uploads a file to the media folder diff --git a/zero.Core/Collections/Media/MediaFolderValidator.cs b/zero.Core/Collections/Media/MediaFolderValidator.cs index 1b298802..20712f66 100644 --- a/zero.Core/Collections/Media/MediaFolderValidator.cs +++ b/zero.Core/Collections/Media/MediaFolderValidator.cs @@ -6,7 +6,7 @@ using zero.Core.Validation; namespace zero.Core.Collections { - public class MediaFolderValidator : ZeroValidator + public class MediaFolderValidator : ZeroValidator { public MediaFolderValidator(IBackofficeStore store) { diff --git a/zero.Core/Collections/Media/MediaValidator.cs b/zero.Core/Collections/Media/MediaValidator.cs index 6df5c4de..4e3b99d6 100644 --- a/zero.Core/Collections/Media/MediaValidator.cs +++ b/zero.Core/Collections/Media/MediaValidator.cs @@ -4,7 +4,7 @@ using zero.Core.Validation; namespace zero.Core.Collections { - public class MediaValidator : ZeroValidator + public class MediaValidator : ZeroValidator { public MediaValidator() { diff --git a/zero.Core/Collections/Translations/TranslationValidator.cs b/zero.Core/Collections/Translations/TranslationValidator.cs index 00be69eb..231044d6 100644 --- a/zero.Core/Collections/Translations/TranslationValidator.cs +++ b/zero.Core/Collections/Translations/TranslationValidator.cs @@ -6,7 +6,7 @@ using zero.Core.Validation; namespace zero.Core.Collections { - public class TranslationValidator : ZeroValidator + public class TranslationValidator : ZeroValidator { public TranslationValidator(IBackofficeStore store) { diff --git a/zero.Core/Collections/Translations/TranslationsCollection.cs b/zero.Core/Collections/Translations/TranslationsCollection.cs index 678e65ed..f1594947 100644 --- a/zero.Core/Collections/Translations/TranslationsCollection.cs +++ b/zero.Core/Collections/Translations/TranslationsCollection.cs @@ -7,9 +7,9 @@ using zero.Core.Entities; namespace zero.Core.Collections { - public class TranslationsCollection : CollectionBase, ITranslationsCollection + public class TranslationsCollection : CollectionBase, ITranslationsCollection { - public TranslationsCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator) : base(context, interceptor, validator) { } + public TranslationsCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator) : base(context, interceptor, validator) { } /// @@ -19,14 +19,14 @@ namespace zero.Core.Collections } /// - public override IAsyncEnumerable Stream() + public override IAsyncEnumerable Stream() { return base.Stream(q => q.OrderByDescending(x => x.Name)); } } - public interface ITranslationsCollection : ICollectionBase + public interface ITranslationsCollection : ICollectionBase { /// /// Get a translated string by id diff --git a/zero.Core/Collections/TreeCollectionBase.cs b/zero.Core/Collections/TreeCollectionBase.cs deleted file mode 100644 index 71c51691..00000000 --- a/zero.Core/Collections/TreeCollectionBase.cs +++ /dev/null @@ -1,59 +0,0 @@ -using FluentValidation; -using Raven.Client; -using Raven.Client.Documents; -using Raven.Client.Documents.Linq; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using zero.Core.Entities; -using zero.Core.Extensions; - -namespace zero.Core.Collections -{ - public abstract class TreeCollectionBase : CollectionBase, ITreeCollectionBase, IDisposable where T : IZeroEntity, ITreeEntity - { - public TreeCollectionBase(IZeroContext context, ICollectionInterceptorHandler interceptorHandler, IValidator validator = null) : base(context, interceptorHandler, validator) { } - - - ///// - //public async Task> GetHierarchy(string id) - //{ - // Categories_ByHierarchy.Result result = await Session.Query() - // .ProjectInto() - // .Include(x => x.Path.Select(p => p.Id)) - // .FirstOrDefaultAsync(x => x.Id == id); - - // if (result == null) - // { - // return new(); - // } - - // return (await Session.LoadAsync(result.Path.Select(x => x.Id))).Select(x => x.Value).ToList(); - //} - } - - - public interface ITreeCollectionBase : ICollectionBase where T : IZeroEntity, ITreeEntity - { - ///// - ///// Get the tree hierarchy path for this entity - ///// - //Task> GetHierarchy(string id); - - ///// - ///// Update sorting of entities on a specific level - ///// - //Task>> SaveSorting(string[] sortedIds); - - ///// - ///// Move an entity to a new parent - ///// - //Task> Move(string id, string parentId); - - ///// - ///// Copies an entity to a new location - ///// - //Task> Copy(string id, string destinationId, bool includeDescendants = false); - } -} diff --git a/zero.Core/Cultures/CultureResolver.cs b/zero.Core/Cultures/CultureResolver.cs index df2978cd..bde2599a 100644 --- a/zero.Core/Cultures/CultureResolver.cs +++ b/zero.Core/Cultures/CultureResolver.cs @@ -33,11 +33,11 @@ namespace zero.Core.Cultures } else { - ILanguage language = await session.Query().FirstOrDefaultAsync(); + Language language = await session.Query().FirstOrDefaultAsync(); if (language == null) { - Logger.LogWarning("Could not set request culture as there is no available ILanguage stored"); + Logger.LogWarning("Could not set request culture as there is no available Language stored"); return CultureInfo.CurrentCulture; } @@ -50,7 +50,7 @@ namespace zero.Core.Cultures } catch (Exception ex) { - Logger.LogError(ex, "Could not create culture from ILanguage code {code}", language.Code); + Logger.LogError(ex, "Could not create culture from Language code {code}", language.Code); return CultureInfo.CurrentCulture; } } diff --git a/zero.Core/Database/Indexes/MediaFolder_ByHierarchy.cs b/zero.Core/Database/Indexes/MediaFolder_ByHierarchy.cs index 541f9cee..c5aac00d 100644 --- a/zero.Core/Database/Indexes/MediaFolder_ByHierarchy.cs +++ b/zero.Core/Database/Indexes/MediaFolder_ByHierarchy.cs @@ -6,12 +6,10 @@ using zero.Core.Entities; namespace zero.Core.Database.Indexes { - public class MediaFolder_ByHierarchy : AbstractIndexCreationTask + public class MediaFolder_ByHierarchy : AbstractIndexCreationTask { - public class Result : IZeroIdEntity, IZeroDbConventions + public class Result : ZeroIdEntity, IZeroDbConventions { - public string Id { get; set; } - public string Name { get; set; } public List Path { get; set; } = new List(); @@ -32,7 +30,7 @@ namespace zero.Core.Database.Indexes { Id = item.Id, Name = item.Name, - Path = Recurse(item, x => LoadDocument(x.ParentId)) + Path = Recurse(item, x => LoadDocument(x.ParentId)) .Where(x => x != null && x.Id != null && x.Id != item.Id) .Reverse() .Select(current => new PathResult() diff --git a/zero.Core/Database/Indexes/MediaFolders_WithChildren.cs b/zero.Core/Database/Indexes/MediaFolders_WithChildren.cs index 401fced8..cbc61d8c 100644 --- a/zero.Core/Database/Indexes/MediaFolders_WithChildren.cs +++ b/zero.Core/Database/Indexes/MediaFolders_WithChildren.cs @@ -7,10 +7,8 @@ namespace zero.Core.Database.Indexes { public class MediaFolders_WithChildren : AbstractIndexCreationTask { - public class Result : IZeroIdEntity, IZeroDbConventions + public class Result : ZeroIdEntity { - public string Id { get; set; } - public string ParentId { get; set; } public string Name { get; set; } diff --git a/zero.Core/Database/Indexes/Media_ByChildren.cs b/zero.Core/Database/Indexes/Media_ByChildren.cs index 4abcfbae..ed35f963 100644 --- a/zero.Core/Database/Indexes/Media_ByChildren.cs +++ b/zero.Core/Database/Indexes/Media_ByChildren.cs @@ -6,10 +6,8 @@ namespace zero.Core.Database.Indexes { public class Media_ByChildren : AbstractMultiMapIndexCreationTask { - public class Result : IZeroIdEntity, IZeroDbConventions + public class Result : ZeroIdEntity, IZeroDbConventions { - public string Id { get; set; } - public string ParentId { get; set; } public int ChildrenCount { get; set; } @@ -20,7 +18,7 @@ namespace zero.Core.Database.Indexes public Media_ByChildren() { - AddMap(items => items.Select(item => new Result() + AddMap(items => items.Select(item => new Result() { Id = item.Id, ParentId = item.FolderId, @@ -28,7 +26,7 @@ namespace zero.Core.Database.Indexes ChildrenIds = new string[] { } })); - AddMap(items => items.Select(item => new Result() + AddMap(items => items.Select(item => new Result() { Id = item.Id, ParentId = item.ParentId, diff --git a/zero.Core/Database/Indexes/Media_ByParent.cs b/zero.Core/Database/Indexes/Media_ByParent.cs index bc85474a..8081a42b 100644 --- a/zero.Core/Database/Indexes/Media_ByParent.cs +++ b/zero.Core/Database/Indexes/Media_ByParent.cs @@ -9,7 +9,7 @@ namespace zero.Core.Database.Indexes { public Media_ByParent() { - AddMap(items => items.Select(item => new MediaListItem + AddMap(items => items.Select(item => new MediaListItem { Id = item.Id, ParentId = item.ParentId, @@ -23,7 +23,7 @@ namespace zero.Core.Database.Indexes AspectRatio = 0 })); - AddMap(items => items.Select(item => new MediaListItem + AddMap(items => items.Select(item => new MediaListItem { Id = item.Id, ParentId = item.FolderId, diff --git a/zero.Core/Database/Indexes/Pages_AsHistory.cs b/zero.Core/Database/Indexes/Pages_AsHistory.cs index 4b33053d..42a96a1b 100644 --- a/zero.Core/Database/Indexes/Pages_AsHistory.cs +++ b/zero.Core/Database/Indexes/Pages_AsHistory.cs @@ -6,12 +6,10 @@ using zero.Core.Entities; namespace zero.Core.Database.Indexes { - public class Pages_AsHistory : AbstractIndexCreationTask + public class Pages_AsHistory : AbstractIndexCreationTask { - public class Result : IZeroIdEntity, IZeroDbConventions + public class Result : ZeroIdEntity, IZeroDbConventions { - public string Id { get; set; } - public DateTimeOffset LastModified { get; set; } } diff --git a/zero.Core/Database/Indexes/Pages_ByHierarchy.cs b/zero.Core/Database/Indexes/Pages_ByHierarchy.cs index 1472c0dc..8e729893 100644 --- a/zero.Core/Database/Indexes/Pages_ByHierarchy.cs +++ b/zero.Core/Database/Indexes/Pages_ByHierarchy.cs @@ -8,10 +8,8 @@ namespace zero.Core.Database.Indexes { public class Pages_ByHierarchy : AbstractIndexCreationTask { - public class Result : IZeroIdEntity, IZeroDbConventions + public class Result : ZeroIdEntity, IZeroDbConventions { - public string Id { get; set; } - public string Name { get; set; } public List Path { get; set; } = new List(); diff --git a/zero.Core/Database/Indexes/Pages_WithChildren.cs b/zero.Core/Database/Indexes/Pages_WithChildren.cs index 24d99d0b..30cec9a1 100644 --- a/zero.Core/Database/Indexes/Pages_WithChildren.cs +++ b/zero.Core/Database/Indexes/Pages_WithChildren.cs @@ -8,10 +8,8 @@ namespace zero.Core.Database.Indexes { public class Pages_WithChildren : AbstractIndexCreationTask { - public class Result : IZeroIdEntity, IZeroDbConventions + public class Result : ZeroIdEntity, IZeroDbConventions { - public string Id { get; set; } - public string ParentId { get; set; } public string Name { get; set; } diff --git a/zero.Core/Database/Indexes/TreeEntity_ByPath.cs b/zero.Core/Database/Indexes/TreeEntity_ByPath.cs index 3ef64fcd..0256f722 100644 --- a/zero.Core/Database/Indexes/TreeEntity_ByPath.cs +++ b/zero.Core/Database/Indexes/TreeEntity_ByPath.cs @@ -8,7 +8,7 @@ //{ // public class TreeEntity_ByPath : AbstractIndexCreationTask // { -// public class Result : IZeroIdEntity, IZeroDbConventions +// public class Result : ZeroIdEntity, IZeroDbConventions // { // public string Id { get; set; } diff --git a/zero.Core/Database/ZeroDocumentConventionsBuilder.cs b/zero.Core/Database/ZeroDocumentConventionsBuilder.cs index 58adbdf3..b5af6cb9 100644 --- a/zero.Core/Database/ZeroDocumentConventionsBuilder.cs +++ b/zero.Core/Database/ZeroDocumentConventionsBuilder.cs @@ -42,7 +42,7 @@ namespace zero.Core.Database conventions.IdentityPartsSeparator = IdentityPartsSeparator; conventions.TransformTypeCollectionNameToDocumentIdPrefix = TransformTypeCollectionNameToDocumentIdPrefix; conventions.FindCollectionName = FindCollectionName; - conventions.RegisterAsyncIdConvention((_, entity) => GetDocumentId(conventions, entity)); + conventions.RegisterAsyncIdConvention((_, entity) => GetDocumentId(conventions, entity)); ConfigureJsonSerializer(conventions.Serialization); } diff --git a/zero.Core/Entities/Applications/Application.cs b/zero.Core/Entities/Applications/Application.cs index cf64d74d..61e565ce 100644 --- a/zero.Core/Entities/Applications/Application.cs +++ b/zero.Core/Entities/Applications/Application.cs @@ -7,68 +7,43 @@ namespace zero.Core.Entities /// /// An application is a website. zero can host multiple websites at once which share common assets /// - public class Application : ZeroEntity, IApplication - { - /// - public string Database { get; set; } - - /// - public string FullName { get; set; } - - /// - public string Email { get; set; } - - /// - public string ImageId { get; set; } - - /// - public string IconId { get; set; } - - /// - public Uri[] Domains { get; set; } = new Uri[] { }; - - /// - public List Features { get; set; } = new List(); - } - - [Collection("Applications")] - public interface IApplication : IZeroEntity, IZeroDbConventions + public class Application : ZeroEntity { /// /// Raven database name for application data /// - string Database { get; set; } + public string Database { get; set; } /// /// Full company or product name /// - string FullName { get; set; } + public string FullName { get; set; } /// /// Generic contact email. Can be used in various locations /// - string Email { get; set; } + public string Email { get; set; } /// /// Image of the application /// - string ImageId { get; set; } + public string ImageId { get; set; } /// /// Simple image of the application (can be used as favicon) /// - string IconId { get; set; } + public string IconId { get; set; } /// /// All assigned domains for this application /// - Uri[] Domains { get; set; } + public Uri[] Domains { get; set; } = Array.Empty(); /// /// Features which are enabled for this application. /// Can be user-defined and affect both backoffice and frontend /// - List Features { get; set; } + public List Features { get; set; } = new(); } } \ No newline at end of file diff --git a/zero.Core/Entities/Country.cs b/zero.Core/Entities/Country.cs index 79e668f2..d80547a4 100644 --- a/zero.Core/Entities/Country.cs +++ b/zero.Core/Entities/Country.cs @@ -1,28 +1,15 @@ -using zero.Core.Attributes; - -namespace zero.Core.Entities +namespace zero.Core.Entities { - public class Country : ZeroEntity, ICountry - { - /// - public bool IsPreferred { get; set; } - - /// - public string Code { get; set; } - } - - - [Collection("Countries")] - public interface ICountry : IZeroEntity, IZeroDbConventions + public class Country : ZeroEntity { /// /// Preferred countries are displayed on top in lists /// - bool IsPreferred { get; set; } + public bool IsPreferred { get; set; } /// /// Country code (ISO 3166-1) /// - string Code { get; set; } + public string Code { get; set; } } } diff --git a/zero.Core/Entities/Features/Feature.cs b/zero.Core/Entities/Features/Feature.cs index 7e249bf2..3b5238ef 100644 --- a/zero.Core/Entities/Features/Feature.cs +++ b/zero.Core/Entities/Features/Feature.cs @@ -1,15 +1,23 @@ namespace zero.Core.Entities { - /// - public class Feature : IFeature + /// + /// A feature can affect both the backoffice and the frontend + /// + public class Feature { - /// + /// + /// The alias + /// public string Alias { get; set; } - /// + /// + /// The name of the feature + /// public string Name { get; set; } - /// + /// + /// Additional description + /// public string Description { get; set; } } } diff --git a/zero.Core/Entities/Features/IFeature.cs b/zero.Core/Entities/Features/IFeature.cs deleted file mode 100644 index 4c6f8ef2..00000000 --- a/zero.Core/Entities/Features/IFeature.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace zero.Core.Entities -{ - /// - /// A feature can affect both the backoffice and the frontend - /// - public interface IFeature - { - /// - /// The alias - /// - string Alias { get; } - - /// - /// The name of the feature - /// - string Name { get; } - - /// - /// Additional description - /// - string Description { get; } - } -} diff --git a/zero.Core/Entities/IAppAwareEntity.cs b/zero.Core/Entities/IAppAwareEntity.cs deleted file mode 100644 index 12fef12a..00000000 --- a/zero.Core/Entities/IAppAwareEntity.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace zero.Core.Entities -{ - /// - /// By default most entities are app aware and stored in their own database context. - /// Exceptions (like media) are stored in the core database and need to be marked as app aware - /// - public interface IAppAwareEntity - { - /// - /// Associated app id of the entity - /// - string AppId { get; set; } - } -} diff --git a/zero.Core/Entities/IExportConfig.cs b/zero.Core/Entities/IExportConfig.cs deleted file mode 100644 index 9d692f44..00000000 --- a/zero.Core/Entities/IExportConfig.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace zero.Core.Entities -{ - public interface IExportConfig - { - } -} diff --git a/zero.Core/Entities/ILanguageAwareEntity.cs b/zero.Core/Entities/ILanguageAwareEntity.cs deleted file mode 100644 index 3f22c487..00000000 --- a/zero.Core/Entities/ILanguageAwareEntity.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace zero.Core.Entities -{ - public interface ILanguageAwareEntity - { - ///// - ///// Contains the parent entity in case this is a language variant - ///// - //public string ParentEntityId { get; set; } - - /// - /// Language of the entity - /// - string LanguageId { get; set; } - } -} diff --git a/zero.Core/Entities/ITreeEntity.cs b/zero.Core/Entities/ITreeEntity.cs deleted file mode 100644 index 0ce9fc19..00000000 --- a/zero.Core/Entities/ITreeEntity.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace zero.Core.Entities -{ - public interface ITreeEntity : IZeroEntity - { - /// - /// Id of the parent entity - /// - string ParentId { get; set; } - } -} diff --git a/zero.Core/Entities/IZeroConfigEntity.cs b/zero.Core/Entities/IZeroConfigEntity.cs deleted file mode 100644 index d10906ab..00000000 --- a/zero.Core/Entities/IZeroConfigEntity.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace zero.Core.Entities -{ - public interface IZeroConfigEntity : IZeroEntity - { - /// - /// Alias of the used type - /// - string TypeAlias { get; set; } - } -} diff --git a/zero.Core/Entities/IZeroIdEntity.cs b/zero.Core/Entities/IZeroIdEntity.cs deleted file mode 100644 index 5ae75b7d..00000000 --- a/zero.Core/Entities/IZeroIdEntity.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace zero.Core.Entities -{ - public interface IZeroIdEntity - { - /// - /// Id of the entity - /// - string Id { get; set; } - } -} \ No newline at end of file diff --git a/zero.Core/Entities/IZeroInternal.cs b/zero.Core/Entities/IZeroInternal.cs deleted file mode 100644 index 40886856..00000000 --- a/zero.Core/Entities/IZeroInternal.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace zero.Core.Entities -{ - public interface IZeroInternal - { - } -} diff --git a/zero.Core/Entities/IconSet.cs b/zero.Core/Entities/IconSet.cs index 3f667aa6..a3dcec95 100644 --- a/zero.Core/Entities/IconSet.cs +++ b/zero.Core/Entities/IconSet.cs @@ -1,44 +1,28 @@ namespace zero.Core.Entities { - /// - public class IconSet : IIconSet - { - /// - public string Alias { get; set; } - - /// - public string Name { get; set; } - - /// - public string Prefix { get; set; } - - /// - public string SpritePath { get; set; } - } - /// /// Define a backoffice icon set /// - public interface IIconSet + public class IconSet { /// /// The alias /// - string Alias { get; } + public string Alias { get; set; } /// /// Name of the icon set /// - string Name { get; } + public string Name { get; set; } /// /// Prefix for addressing symbols (by default the alias) /// - string Prefix { get; } + public string Prefix { get; set; } /// /// Path to the SVG sprite /// - string SpritePath { get; } + public string SpritePath { get; set; } } } diff --git a/zero.Core/Entities/InheritAttribute.cs b/zero.Core/Entities/InheritAttribute.cs deleted file mode 100644 index 8b1e17c2..00000000 --- a/zero.Core/Entities/InheritAttribute.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -namespace zero.Core.Entities -{ - public class OverwriteAttribute : Attribute - { - } - - - public class ReferenceAttribute : Attribute - { - public Type Type { get; set; } - - public ReferenceAttribute(Type type) - { - Type = type; - } - } -} \ No newline at end of file diff --git a/zero.Core/Entities/Language.cs b/zero.Core/Entities/Language.cs index 52f0b93b..63aa61ce 100644 --- a/zero.Core/Entities/Language.cs +++ b/zero.Core/Entities/Language.cs @@ -2,42 +2,27 @@ namespace zero.Core.Entities { - public class Language : ZeroEntity, ILanguage - { - /// - public string Code { get; set; } - - /// - public bool IsDefault { get; set; } - - /// - public bool IsOptional { get; set; } - - /// - public string InheritedLanguageId { get; set; } - } - [Collection("Languages")] - public interface ILanguage : IZeroEntity, IZeroDbConventions + public class Language : ZeroEntity { /// /// Language code (ISO 3166-1) /// - string Code { get; set; } + public string Code { get; set; } /// /// Whether this is the default language /// - bool IsDefault { get; set; } + public bool IsDefault { get; set; } /// /// Whether this language is optional and does not have to be filled out /// - bool IsOptional { get; set; } + public bool IsOptional { get; set; } /// /// If this language is inherited it gets all missing properties from its parent /// - string InheritedLanguageId { get; set; } + public string InheritedLanguageId { get; set; } } } \ No newline at end of file diff --git a/zero.Core/Entities/LanguageVariant.cs b/zero.Core/Entities/LanguageVariant.cs deleted file mode 100644 index 1a328843..00000000 --- a/zero.Core/Entities/LanguageVariant.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace zero.Core.Entities -{ - public class LanguageVariant - { - public string LanguageId { get; set; } - - public string Name { get; set; } - - public bool HideEntity { get; set; } - } - - - public interface ILanguageVariant - { - string LanguageId { get; set; } - } -} diff --git a/zero.Core/Entities/Links/Link.cs b/zero.Core/Entities/Links/Link.cs index c8d7285e..c3a1271c 100644 --- a/zero.Core/Entities/Links/Link.cs +++ b/zero.Core/Entities/Links/Link.cs @@ -1,10 +1,9 @@ using Newtonsoft.Json; -using System; using System.Collections.Generic; namespace zero.Core.Entities { - public class Link : ILink + public class Link { public string Area { get; set; } @@ -16,7 +15,10 @@ namespace zero.Core.Entities public Dictionary Values { get; set; } = new(); - /// + /// + /// [Warning] This field is always empty when bound to the database. + /// It is only filled in the app-code for routing. + /// [JsonIgnore] public string Url { get; set; } } @@ -27,25 +29,4 @@ namespace zero.Core.Entities Self = 1, Blank = 2 } - - - public interface ILink - { - string Area { get; set; } - - LinkTarget Target { get; set; } - - string UrlSuffix { get; set; } - - string Title { get; set; } - - Dictionary Values { get; set; } - - /// - /// [Warning] This field is always empty when bound to the database. - /// It is only filled in the app-code for routing. - /// - [JsonIgnore] - public string Url { get; set; } - } } diff --git a/zero.Core/Entities/Links/LinkArea.cs b/zero.Core/Entities/Links/LinkArea.cs deleted file mode 100644 index c2c70f0b..00000000 --- a/zero.Core/Entities/Links/LinkArea.cs +++ /dev/null @@ -1,72 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using System.Linq; -//using System.Text; -//using System.Threading.Tasks; - -//namespace zero.Core.Entities -//{ -// /// -// public class LinkArea : ILinkArea -// { -// /// -// public string Alias { get; set; } - -// /// -// public string Name { get; set; } - -// /// -// public string Icon { get; set; } - -// /// -// /// HEX color (#aabbcc or #abc). Defaults to a neutral color -// /// -// public string Color { get; set; } - -// /// -// public IList Children { get; } = new List(); - - -// public LinkArea() { } - -// public LinkArea(string alias, string name, string icon = null, string color = null) -// { -// Alias = alias; -// Name = name; -// Icon = icon; -// Color = color; -// } -// } - - -// /// -// /// A section is a main part of the backoffice application -// /// -// public interface ILinkArea -// { -// /// -// /// The section alias which acts as the url slug for navigation -// /// -// string Alias { get; } - -// /// -// /// The name of the section (either a string or a translation key with @ prefix) -// /// -// string Name { get; } - -// /// -// /// Icon of the section -// /// -// string Icon { get; } - -// /// -// /// HEX color (#aabbcc or #abc) -// /// -// string Color { get; } - -// /// -// /// Children are displayed as a sub-navigation in the main nav area -// /// -// IList Children { get; } -// } -//} diff --git a/zero.Core/Entities/MailTemplate.cs b/zero.Core/Entities/MailTemplate.cs index 64f6e821..30aa4510 100644 --- a/zero.Core/Entities/MailTemplate.cs +++ b/zero.Core/Entities/MailTemplate.cs @@ -1,77 +1,48 @@ using zero.Core.Attributes; -using zero.Core.Entities; namespace zero.Core.Entities { - public class MailTemplate : ZeroEntity, IMailTemplate - { - /// - public string SenderEmail { get; set; } - - /// - public string SenderName { get; set; } - - /// - public string RecipientEmail { get; set; } - - /// - public string Cc { get; set; } - - /// - public string Bcc { get; set; } - - /// - public string Subject { get; set; } - - /// - public string Body { get; set; } - - /// - public string Preheader { get; set; } - } - - [Collection("MailTemplates")] - public interface IMailTemplate : IZeroEntity, IZeroDbConventions + public class MailTemplate : ZeroEntity { /// /// Email address of the sender (overrides email from application) /// - string SenderEmail { get; set; } + public string SenderEmail { get; set; } /// /// Name of the sender (overrides name from application) /// - string SenderName { get; set; } + public string SenderName { get; set; } /// /// Email address of the recipient. This is only necessary for templates which do not have a dynamic recipient (e.g. reports). /// - string RecipientEmail { get; set; } + public string RecipientEmail { get; set; } /// /// Additional comma-separated emails to send a copy to /// - string Cc { get; set; } + public string Cc { get; set; } /// /// Additional comma-separated emails to send a hidden copy to /// - string Bcc { get; set; } + public string Bcc { get; set; } /// /// Email subject (can contain placeholders) /// - string Subject { get; set; } + public string Subject { get; set; } /// /// Email body (can contain placeholders) /// - string Body { get; set; } + public string Body { get; set; } /// /// Preheader which is displayed in the preview pane (can contain placeholders) /// - string Preheader { get; set; } + public string Preheader { get; set; } } } \ No newline at end of file diff --git a/zero.Core/Entities/Media/Media.cs b/zero.Core/Entities/Media/Media.cs index ee870bde..d8de19a4 100644 --- a/zero.Core/Entities/Media/Media.cs +++ b/zero.Core/Entities/Media/Media.cs @@ -1,54 +1,12 @@ -using System; -using zero.Core.Attributes; +using zero.Core.Attributes; namespace zero.Core.Entities { - /// - public class Media : ZeroEntity, IMedia - { - /// - public string AppId { get; set; } - - /// - public string FileId { get; set; } - - /// - public string FolderId { get; set; } - - /// - public string AlternativeText { get; set; } - - /// - public string Caption { get; set; } - - /// - public string Source { get; set; } - - /// - public string ThumbnailSource { get; set; } - - /// - public string PreviewSource { get; set; } - - /// - public long Size { get; set; } - - /// - public MediaImageMeta ImageMeta { get; set; } - - /// - public MediaFocalPoint FocalPoint { get; set; } - - /// - public MediaType Type { get; set; } - } - - /// /// A media file (can contain an image or other media like videos and documents) /// [Collection("Media")] - public interface IMedia : IZeroEntity, IZeroDbConventions, IAppAwareEntity + public class Media : ZeroEntity { /// /// Id/name of the phyiscal folder which is stored on disk/cloud @@ -63,46 +21,46 @@ namespace zero.Core.Entities /// /// Alternative text which is used when the image can't be loaded /// - string AlternativeText { get; set; } + public string AlternativeText { get; set; } /// /// Additional caption text /// - string Caption { get; set; } + public string Caption { get; set; } /// /// Path of the media item /// - string Source { get; set; } + public string Source { get; set; } /// /// For images this is the source for a 100x100px thumbnail /// - string ThumbnailSource { get; set; } + public string ThumbnailSource { get; set; } /// /// For images this is the source for a [proportional]x210px thumbnail /// - string PreviewSource { get; set; } + public string PreviewSource { get; set; } /// /// Filesize in bytes /// - long Size { get; set; } + public long Size { get; set; } /// /// Meta data for images /// - MediaImageMeta ImageMeta { get; set; } + public MediaImageMeta ImageMeta { get; set; } /// /// Optional focal point for an image /// - MediaFocalPoint FocalPoint { get; set; } + public MediaFocalPoint FocalPoint { get; set; } /// /// Type of the media /// - MediaType Type { get; set; } + public MediaType Type { get; set; } } } diff --git a/zero.Core/Entities/Media/MediaFolder.cs b/zero.Core/Entities/Media/MediaFolder.cs index 70b8d7dd..e92bda9f 100644 --- a/zero.Core/Entities/Media/MediaFolder.cs +++ b/zero.Core/Entities/Media/MediaFolder.cs @@ -2,26 +2,15 @@ namespace zero.Core.Entities { - /// - public class MediaFolder : ZeroEntity, IMediaFolder - { - /// - public string AppId { get; set; } - - /// - public string ParentId { get; set; } - } - - /// /// A media folder contains media and other folders /// [Collection("MediaFolders")] - public interface IMediaFolder : IZeroEntity, IZeroDbConventions, IAppAwareEntity + public class MediaFolder : ZeroEntity { /// /// Parent folder id /// - string ParentId { get; set; } + public string ParentId { get; set; } } } \ No newline at end of file diff --git a/zero.Core/Entities/Media/MediaListItem.cs b/zero.Core/Entities/Media/MediaListItem.cs index b7d1cfde..c812073d 100644 --- a/zero.Core/Entities/Media/MediaListItem.cs +++ b/zero.Core/Entities/Media/MediaListItem.cs @@ -2,10 +2,8 @@ namespace zero.Core.Entities { - public class MediaListItem : IZeroIdEntity, IZeroDbConventions + public class MediaListItem : ZeroIdEntity { - public string Id { get; set; } - public string ParentId { get; set; } public string Name { get; set; } diff --git a/zero.Core/Entities/Media/MediaListQuery.cs b/zero.Core/Entities/Media/MediaListQuery.cs index 3e48046e..c36f07f5 100644 --- a/zero.Core/Entities/Media/MediaListQuery.cs +++ b/zero.Core/Entities/Media/MediaListQuery.cs @@ -1,6 +1,6 @@ namespace zero.Core.Entities { - public class MediaListQuery : ListQuery + public class MediaListQuery : ListQuery { public string FolderId { get; set; } } diff --git a/zero.Core/Entities/Modules/Module.cs b/zero.Core/Entities/Modules/Module.cs index 3cbbf91a..b91a6cee 100644 --- a/zero.Core/Entities/Modules/Module.cs +++ b/zero.Core/Entities/Modules/Module.cs @@ -1,42 +1,24 @@ -using System; - -namespace zero.Core.Entities +namespace zero.Core.Entities { /// /// A module can consist of unlimited properties and be rendered as you wish /// The backoffice rendering is done by an IRenderer /// - public class Module : IModule - { - /// - public string Id { get; set; } - - /// - public uint Sort { get; set; } - - /// - public bool IsActive { get; set; } - - /// - public string ModuleTypeAlias { get; set; } - } - - - public interface IModule : IZeroIdEntity + public class Module : ZeroIdEntity { /// /// Sort order /// - uint Sort { get; set; } + public uint Sort { get; set; } /// /// Whether the module is visible in the frontend /// - bool IsActive { get; set; } + public bool IsActive { get; set; } /// /// Alias of the used module type /// - string ModuleTypeAlias { get; set; } + public string ModuleTypeAlias { get; set; } } } \ No newline at end of file diff --git a/zero.Core/Entities/Pages/Page.cs b/zero.Core/Entities/Pages/Page.cs index 2414dfde..c136e3be 100644 --- a/zero.Core/Entities/Pages/Page.cs +++ b/zero.Core/Entities/Pages/Page.cs @@ -7,46 +7,30 @@ namespace zero.Core.Entities /// A page can consist of unlimited properties and be rendered as you wish /// The backoffice rendering is done by an IRenderer /// - public class Page : ZeroEntity, IPage + [Collection("Pages")] + public class Page : ZeroEntity { - /// + /// + /// Use this field (when filled out) instead of the alias for URL generation + /// public string UrlAlias { get; set; } /// public string ParentId { get; set; } - /// - public string PageTypeAlias { get; set; } - - /// - public DateTimeOffset? PublishDate { get; set; } - - /// - public DateTimeOffset? UnpublishDate { get; set; } - } - - - [Collection("Pages")] - public interface IPage : IZeroEntity, IZeroDbConventions, ITreeEntity - { - /// - /// Use this field (when filled out) instead of the alias for URL generation - /// - string UrlAlias { get; set; } - /// /// Alias of the used page type /// - string PageTypeAlias { get; set; } + public string PageTypeAlias { get; set; } /// /// Date when the page is published /// - DateTimeOffset? PublishDate { get; set; } + public DateTimeOffset? PublishDate { get; set; } /// /// Date when the page is unpublished /// - DateTimeOffset? UnpublishDate { get; set; } + public DateTimeOffset? UnpublishDate { get; set; } } } \ No newline at end of file diff --git a/zero.Core/Entities/Preset.cs b/zero.Core/Entities/Preset.cs index 9d7a83b3..e764af60 100644 --- a/zero.Core/Entities/Preset.cs +++ b/zero.Core/Entities/Preset.cs @@ -3,50 +3,31 @@ using zero.Core.Attributes; namespace zero.Core.Entities { - public abstract class Preset : IPreset - { - /// - public string Key { get; set; } - - /// - public string Name { get; set; } - } - - public interface IPreset + public abstract class Preset { /// /// Key is used to query a preset /// - string Key { get; set; } + public string Key { get; set; } /// /// Name of the preset /// - string Name { get; set; } - } - - - public class PresetOverride : ZeroEntity, IPresetOverride where T : IPreset - { - /// - public Type TargetType { get; set; } - - /// - public T Model { get; set; } + public string Name { get; set; } } [Collection("Presets")] - public interface IPresetOverride : IZeroEntity, IZeroDbConventions where T : IPreset + public class PresetOverride : ZeroEntity where T : Preset { /// /// Type of the target model (used to query) /// - Type TargetType { get; set; } + public Type TargetType { get; set; } /// /// Overridden data /// - T Model { get; set; } + public T Model { get; set; } } } diff --git a/zero.Core/Entities/Preview.cs b/zero.Core/Entities/Preview.cs index a88a5250..a8ff2346 100644 --- a/zero.Core/Entities/Preview.cs +++ b/zero.Core/Entities/Preview.cs @@ -2,27 +2,17 @@ namespace zero.Core.Entities { - public class Preview : ZeroEntity, IPreview - { - /// - public string OriginalId { get; set; } - - /// - public IZeroEntity Content { get; set; } - } - - [Collection("Previews")] - public interface IPreview : IZeroEntity, IZeroDbConventions + public class Preview : ZeroEntity { /// /// Id of the original entity /// - string OriginalId { get; set; } + public string OriginalId { get; set; } /// /// Contains the entity content /// - IZeroEntity Content { get; set; } + public ZeroEntity Content { get; set; } } } diff --git a/zero.Core/Entities/RecycleBin/RecycleBinListQuery.cs b/zero.Core/Entities/RecycleBin/RecycleBinListQuery.cs index 852871be..2abe5dbf 100644 --- a/zero.Core/Entities/RecycleBin/RecycleBinListQuery.cs +++ b/zero.Core/Entities/RecycleBin/RecycleBinListQuery.cs @@ -1,6 +1,6 @@ namespace zero.Core.Entities { - public class RecycleBinListQuery : ListQuery + public class RecycleBinListQuery : ListQuery { public string Group { get; set; } diff --git a/zero.Core/Entities/RecycleBin/RecycledEntity.cs b/zero.Core/Entities/RecycleBin/RecycledEntity.cs index 34d8026c..4ceb0084 100644 --- a/zero.Core/Entities/RecycleBin/RecycledEntity.cs +++ b/zero.Core/Entities/RecycleBin/RecycledEntity.cs @@ -2,43 +2,27 @@ namespace zero.Core.Entities { - public class RecycledEntity : ZeroEntity, IRecycledEntity - { - /// - public string OriginalId { get; set; } - - /// - public string OperationId { get; set; } - - /// - public string Group { get; set; } - - /// - public IZeroEntity Content { get; set; } - } - - [Collection("RecycleBin")] - public interface IRecycledEntity : IZeroEntity, IZeroDbConventions + public class RecycledEntity : ZeroEntity { /// /// Id of the recycled entity /// - string OriginalId { get; set; } + public string OriginalId { get; set; } /// /// Group recycled entities together which have been recycled in a single operation /// - string OperationId { get; set; } + public string OperationId { get; set; } /// /// Contains the entity content /// - IZeroEntity Content { get; set; } + public ZeroEntity Content { get; set; } /// /// Recycled entities can be grouped together (e.g. pages, media, ...) /// - string Group { get; set; } + public string Group { get; set; } } } diff --git a/zero.Core/Entities/Refs/Ref.cs b/zero.Core/Entities/Refs/Ref.cs index 48c3478e..2934ad5f 100644 --- a/zero.Core/Entities/Refs/Ref.cs +++ b/zero.Core/Entities/Refs/Ref.cs @@ -1,6 +1,6 @@ namespace zero.Core.Entities { - public class Ref : Ref where T : IZeroIdEntity + public class Ref : Ref where T : ZeroIdEntity { public Ref() : base() { } public Ref(string id) : base(id) { } diff --git a/zero.Core/Entities/Refs/ValueRef.cs b/zero.Core/Entities/Refs/ValueRef.cs index b3782db8..dec86607 100644 --- a/zero.Core/Entities/Refs/ValueRef.cs +++ b/zero.Core/Entities/Refs/ValueRef.cs @@ -1,6 +1,6 @@ namespace zero.Core.Entities { - public class ValueRef : ValueRef where T : IZeroIdEntity + public class ValueRef : ValueRef where T : ZeroIdEntity { public ValueRef() : base() { } public ValueRef(string id, string value) : base(id, value) { } @@ -9,7 +9,7 @@ } - public class ValueRef : Ref where TEntity : IZeroIdEntity + public class ValueRef : Ref where TEntity : ZeroIdEntity { public ValueRef() : base() { } public ValueRef(string id, TValue value) : base(id) diff --git a/zero.Core/Entities/Sections/ISection.cs b/zero.Core/Entities/Sections/ISection.cs index 4c32cc49..66a3e665 100644 --- a/zero.Core/Entities/Sections/ISection.cs +++ b/zero.Core/Entities/Sections/ISection.cs @@ -2,6 +2,11 @@ namespace zero.Core.Entities { + /// + /// Internal section + /// + public interface IInternalSection : ISection { } + /// /// A section is a main part of the backoffice application /// diff --git a/zero.Core/Entities/Settings/SettingsArea.cs b/zero.Core/Entities/Settings/SettingsArea.cs index f1e7adb3..b95b7c9d 100644 --- a/zero.Core/Entities/Settings/SettingsArea.cs +++ b/zero.Core/Entities/Settings/SettingsArea.cs @@ -38,7 +38,7 @@ } - public class InternalSettingsArea : SettingsArea, IZeroInternal + public class InternalSettingsArea : SettingsArea { public InternalSettingsArea() { } public InternalSettingsArea(string alias, string name, string description = null, string icon = null) : base(alias, name, description, icon) { } diff --git a/zero.Core/Entities/Settings/SettingsGroup.cs b/zero.Core/Entities/Settings/SettingsGroup.cs index a46b2c89..2af7d501 100644 --- a/zero.Core/Entities/Settings/SettingsGroup.cs +++ b/zero.Core/Entities/Settings/SettingsGroup.cs @@ -2,6 +2,8 @@ namespace zero.Core.Entities { + public class InternalSettingsGroup : SettingsGroup { } + public class SettingsGroup { public string Name { get; set; } diff --git a/zero.Core/Entities/Spaces/Space.cs b/zero.Core/Entities/Spaces/Space.cs index d5458a1a..9575311c 100644 --- a/zero.Core/Entities/Spaces/Space.cs +++ b/zero.Core/Entities/Spaces/Space.cs @@ -2,7 +2,7 @@ namespace zero.Core.Entities { - public class Space : ISpace + public class Space { public string Alias { get; set; } @@ -22,26 +22,4 @@ namespace zero.Core.Entities public bool LineBelow { get; set; } } - - public interface ISpace - { - string Alias { get; set; } - - string EditorAlias { get; set; } - - string ComponentPath { get; set; } - - string Description { get; set; } - - string Icon { get; set; } - - bool LineBelow { get; set; } - - string Name { get; set; } - - Type Type { get; set; } - - SpaceView View { get; set; } - - } } \ No newline at end of file diff --git a/zero.Core/Entities/Spaces/SpaceContent.cs b/zero.Core/Entities/Spaces/SpaceContent.cs index 65b3098e..9fbbcbbd 100644 --- a/zero.Core/Entities/Spaces/SpaceContent.cs +++ b/zero.Core/Entities/Spaces/SpaceContent.cs @@ -2,27 +2,16 @@ namespace zero.Core.Entities { - /// - /// A list item can consist of unlimited properties and be rendered as you wish - /// The backoffice rendering is done by an IRenderer - /// - public class SpaceContent : ZeroEntity, ISpaceContent - { - /// - public string SpaceAlias { get; set; } - } - - /// /// A list item can consist of unlimited properties and be rendered as you wish /// The backoffice rendering is done by an IRenderer /// [Collection("SpaceContents")] - public interface ISpaceContent : IZeroEntity, IZeroDbConventions + public class SpaceContent : ZeroEntity { /// /// Associated space /// - string SpaceAlias { get; set; } + public string SpaceAlias { get; set; } } } \ No newline at end of file diff --git a/zero.Core/Entities/Spaces/SpaceView.cs b/zero.Core/Entities/Spaces/SpaceView.cs index a0f031a4..acbaf821 100644 --- a/zero.Core/Entities/Spaces/SpaceView.cs +++ b/zero.Core/Entities/Spaces/SpaceView.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace zero.Core.Entities +namespace zero.Core.Entities { public enum SpaceView { diff --git a/zero.Core/Entities/Translation.cs b/zero.Core/Entities/Translation.cs index cd5221d4..67293624 100644 --- a/zero.Core/Entities/Translation.cs +++ b/zero.Core/Entities/Translation.cs @@ -1,17 +1,16 @@ -using zero.Core.Attributes; - -namespace zero.Core.Entities +namespace zero.Core.Entities { - public class Translation : ZeroEntity, ITranslation + public class Translation : ZeroEntity { - /// - public string LanguageId { get; set; } - - /// + /// + /// Value of the translation + /// public string Value { get; set; } - /// - public TranslationDisplay Display { get; set; } + /// + /// Display + input type + /// + public TranslationDisplay Display { get; set; } } @@ -20,19 +19,4 @@ namespace zero.Core.Entities Text = 0, HTML = 1 } - - - [Collection("Translations")] - public interface ITranslation : IZeroEntity, ILanguageAwareEntity, IZeroDbConventions - { - /// - /// Value of the translation - /// - string Value { get; set; } - - /// - /// Display + input type - /// - TranslationDisplay Display { 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 6ebc0ccb..72aaa1af 100644 --- a/zero.Core/Entities/User/BackofficeUser.cs +++ b/zero.Core/Entities/User/BackofficeUser.cs @@ -1,101 +1,28 @@ -using System; -using System.Collections.Generic; -using zero.Core.Attributes; -using zero.Core.Identity; +using zero.Core.Attributes; namespace zero.Core.Entities { - public class BackofficeUser : ZeroEntity, IBackofficeUser - { - /// - public string Username { get; set; } - - /// - public string AppId { get; set; } - - /// - public string CurrentAppId { get; set; } - - /// - public bool IsSuper { get; set; } - - /// - public string Email { get; set; } - - /// - public bool IsEmailConfirmed { get; set; } - - /// - public string PasswordHash { get; set; } - - /// - public string SecurityStamp { get; set; } - - /// - public string AvatarId { get; set; } - - /// - public string LanguageId { get; set; } - - - - /// - public List RoleIds { get; set; } = new List(); - - /// - public List Claims { get; set; } = new List(); - - - - /// - public int AccessFailedCount { get; set; } - - /// - public bool LockoutEnabled { get; set; } - - /// - public DateTimeOffset? LockoutEnd { get; set; } - - - - ///// - //public bool TwoFactorEnabled { get; set; } - - ///// - //public string TwoFactorAuthenticatorKey { get; set; } - - ///// - //public List TwoFactorRecoveryCodes { get; set; } = new List(); - } - - [Collection("Users")] - public interface IBackofficeUser : IZeroEntity, IZeroDbConventions, IIdentityUserWithRoles + public class BackofficeUser : ZeroIdentityUser { /// /// Application the user registered in /// - string AppId { get; set; } + public string AppId { get; set; } /// /// Currently selected app id for the backoffice /// - string CurrentAppId { get; set; } + public string CurrentAppId { get; set; } /// - /// sudo. - /// The user who created the instance. + /// Super user /// - bool IsSuper { get; set; } + public bool IsSuper { get; set; } /// /// Avatar image /// - string AvatarId { get; set; } - - /// - /// Backoffice display language - /// - string LanguageId { get; set; } + public string AvatarId { get; set; } } } diff --git a/zero.Core/Entities/User/BackofficeUserRole.cs b/zero.Core/Entities/User/BackofficeUserRole.cs index 9e81965f..55324988 100644 --- a/zero.Core/Entities/User/BackofficeUserRole.cs +++ b/zero.Core/Entities/User/BackofficeUserRole.cs @@ -1,33 +1,18 @@ -using System.Collections.Generic; -using zero.Core.Attributes; -using zero.Core.Identity; +using zero.Core.Attributes; namespace zero.Core.Entities { - public class BackofficeUserRole : ZeroEntity, IBackofficeUserRole, IZeroDbConventions - { - /// - public string Description { get; set; } - - /// - public string Icon { get; set; } - - /// - public List Claims { get; set; } = new List(); - } - - [Collection("Roles")] - public interface IBackofficeUserRole : IZeroEntity, IZeroDbConventions, IIdentityUserRole + public class BackofficeUserRole : ZeroIdentityRole { /// /// Additional description /// - string Description { get; set; } + public string Description { get; set; } /// /// Displayed icon alongside name /// - string Icon { get; set; } + public string Icon { get; set; } } } \ No newline at end of file diff --git a/zero.Core/Entities/User/UserClaim.cs b/zero.Core/Entities/User/UserClaim.cs index 5d2aa929..8056f238 100644 --- a/zero.Core/Entities/User/UserClaim.cs +++ b/zero.Core/Entities/User/UserClaim.cs @@ -4,15 +4,21 @@ using System.Security.Claims; namespace zero.Core.Entities { - public class UserClaim : IUserClaim + public class UserClaim { - /// + /// + /// Gets or sets the claim type for this claim + /// public string Type { get; set; } - /// + /// + /// Gets or sets the claim value for this claim + /// public string Value { get; set; } - /// + /// + /// Convert to a claim + /// public Claim ToClaim() => new Claim(Type, Value); public UserClaim() { } @@ -38,34 +44,14 @@ namespace zero.Core.Entities - public interface IUserClaim + public class UserClaimComparer : IEqualityComparer { - /// - /// Gets or sets the claim type for this claim - /// - string Type { get; set; } - - /// - /// Gets or sets the claim value for this claim - /// - string Value { get; set; } - - /// - /// Convert to a claim - /// - /// - Claim ToClaim(); - } - - - public class UserClaimComparer : IEqualityComparer - { - public bool Equals(IUserClaim x, IUserClaim y) + public bool Equals(UserClaim x, UserClaim y) { return (x == null && y == null) || (x.Type.Equals(y.Type, StringComparison.InvariantCultureIgnoreCase) && x.Value.Equals(y.Value, StringComparison.InvariantCultureIgnoreCase)); } - public int GetHashCode(IUserClaim obj) + public int GetHashCode(UserClaim obj) { return (obj.Type + obj.Value).GetHashCode(); } diff --git a/zero.Core/Entities/User/ZeroIdentityRole.cs b/zero.Core/Entities/User/ZeroIdentityRole.cs new file mode 100644 index 00000000..0ce8b0e8 --- /dev/null +++ b/zero.Core/Entities/User/ZeroIdentityRole.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace zero.Core.Entities +{ + public abstract class ZeroIdentityRole : ZeroEntity + { + /// + /// The role's claims, for use in claims-based authentication. + /// + public List Claims { get; set; } = new(); + } +} diff --git a/zero.Core/Identity/IIdentityUser.cs b/zero.Core/Entities/User/ZeroIdentityUser.cs similarity index 62% rename from zero.Core/Identity/IIdentityUser.cs rename to zero.Core/Entities/User/ZeroIdentityUser.cs index b45c9ee0..7141c6dd 100644 --- a/zero.Core/Identity/IIdentityUser.cs +++ b/zero.Core/Entities/User/ZeroIdentityUser.cs @@ -1,82 +1,77 @@ using System; using System.Collections.Generic; -using zero.Core.Entities; -namespace zero.Core.Identity +namespace zero.Core.Entities { - public interface IIdentityUserWithRoles : IIdentityUser - { - /// - /// The roles (aliases) of the user - /// - List RoleIds { get; set; } - } - - - public interface IIdentityUser : IZeroEntity + public abstract class ZeroIdentityUser : ZeroEntity { /// /// Optional username (can also be used as login when configured) /// - string Username { get; set; } + public string Username { get; set; } /// /// E-Mail address which is also used as the username /// - string Email { get; set; } + public string Email { get; set; } /// /// Whether the email address has been confirmed /// - bool IsEmailConfirmed { get; set; } + public bool IsEmailConfirmed { get; set; } /// /// The password hash /// - string PasswordHash { get; set; } + public string PasswordHash { get; set; } /// /// The security stamp /// - string SecurityStamp { get; set; } + public string SecurityStamp { get; set; } /// /// The user's claims, for use in claims-based authentication. /// - List Claims { get; set; } + public List Claims { get; set; } = new(); + + /// + /// The roles (aliases) of the user + /// + public List RoleIds { get; set; } = new(); /// /// Number of times sign in failed. /// - int AccessFailedCount { get; set; } + public int AccessFailedCount { get; set; } /// /// Whether the user is locked out. /// - bool LockoutEnabled { get; set; } + public bool LockoutEnabled { get; set; } /// /// When the user lock out is over. /// - DateTimeOffset? LockoutEnd { get; set; } + public DateTimeOffset? LockoutEnd { get; set; } ///// ///// Whether 2-factor authentication is enabled or not ///// - //bool TwoFactorEnabled { get; set; } + //public bool TwoFactorEnabled { get; set; } ///// ///// The two-factor authenticator key ///// - //string TwoFactorAuthenticatorKey { get; set; } + //public string TwoFactorAuthenticatorKey { get; set; } ///// ///// The list of two factor authentication recovery codes ///// - //List TwoFactorRecoveryCodes { get; set; } + //public List TwoFactorRecoveryCodes { get; set; } } } diff --git a/zero.Core/Entities/ZeroEntity.cs b/zero.Core/Entities/ZeroEntity.cs index e57d69c9..d0132e12 100644 --- a/zero.Core/Entities/ZeroEntity.cs +++ b/zero.Core/Entities/ZeroEntity.cs @@ -5,81 +5,37 @@ using System.Diagnostics; namespace zero.Core.Entities { [DebuggerDisplay("Id = {Id,nq}, Name = {Name}, Alias = {Alias}")] - public abstract class ZeroEntity : IZeroEntity - { - /// - public string Id { get; set; } - - /// - public string Name { get; set; } - - /// - public string Alias { get; set; } - - /// - public string Key { get; set; } - - /// - public uint Sort { get; set; } - - /// - public bool IsActive { get; set; } - - /// - public string Hash { get; set; } - - /// - public string LastModifiedById { get; set; } - - /// - public DateTimeOffset LastModifiedDate { get; set; } - - /// - public string CreatedById { get; set; } - - /// - public DateTimeOffset CreatedDate { get; set; } - - /// - public BlueprintConfiguration Blueprint { get; set; } - - /// - [JsonIgnore] - public string Url { get; set; } - } - - - public interface IZeroEntity : IZeroIdEntity + public abstract class ZeroEntity : ZeroIdEntity, IZeroDbConventions { /// /// Full name of the entity /// - string Name { get; set; } + public string Name { get; set; } /// /// Unique alias which can be used in the frontend and URLs /// - string Alias { get; set; } + public string Alias { get; set; } /// /// A key which can be used to query this entity in code /// - string Key { get; set; } + public string Key { get; set; } /// /// Sort order /// - uint Sort { get; set; } + public uint Sort { get; set; } /// /// Whether the entity is visible in the frontend /// - bool IsActive { get; set; } + public bool IsActive { get; set; } /// /// Unique hash for this entity (primarily used for routing) /// - string Hash { get; set; } + public string Hash { get; set; } /// /// Backoffice user who last modified this content @@ -89,23 +45,27 @@ namespace zero.Core.Entities /// /// Date of last modification /// - DateTimeOffset LastModifiedDate { get; set; } + public DateTimeOffset LastModifiedDate { get; set; } /// /// Backoffice user who created this content /// - [Overwrite] public string CreatedById { get; set; } /// /// Date of creation /// - DateTimeOffset CreatedDate { get; set; } + public DateTimeOffset CreatedDate { get; set; } /// /// Configuration of the base entity (which this one inherits from) /// - BlueprintConfiguration Blueprint { get; set; } + public BlueprintConfiguration Blueprint { get; set; } + + /// + /// Language of the entity + /// + public string LanguageId { get; set; } /// /// [Warning] This field is always empty when bound to the database. @@ -114,4 +74,13 @@ namespace zero.Core.Entities [JsonIgnore] public string Url { get; set; } } + + + public abstract class ZeroIdEntity + { + /// + /// Id of the entity + /// + public string Id { get; set; } + } } diff --git a/zero.Core/Entities/ZeroReference.cs b/zero.Core/Entities/ZeroReference.cs index 6fda4079..c60b3837 100644 --- a/zero.Core/Entities/ZeroReference.cs +++ b/zero.Core/Entities/ZeroReference.cs @@ -6,18 +6,18 @@ namespace zero.Core.Entities { public ZeroReference() { } - public ZeroReference(IZeroEntity entity) + public ZeroReference(ZeroEntity entity) { Id = entity.Id; Name = entity.Name; } - public static ZeroReference From(IZeroEntity entity) + public static ZeroReference From(ZeroEntity entity) { return entity == null ? null : new ZeroReference(entity); } - public static ZeroReference From(T entity, Func transform) where T : IZeroEntity + public static ZeroReference From(T entity, Func transform) where T : ZeroEntity { return entity == null ? null : new ZeroReference() { diff --git a/zero.Core/Extensions/BackofficeUserExtensions.cs b/zero.Core/Extensions/BackofficeUserExtensions.cs index 620e16fa..ce3c4b34 100644 --- a/zero.Core/Extensions/BackofficeUserExtensions.cs +++ b/zero.Core/Extensions/BackofficeUserExtensions.cs @@ -7,7 +7,7 @@ namespace zero.Core.Extensions { public static class BackofficeUserExtensions { - public static string[] GetAllowedAppIds(this IBackofficeUser user) + public static string[] GetAllowedAppIds(this BackofficeUser user) { if (user == null) { diff --git a/zero.Core/Extensions/EnumerableExtensions.cs b/zero.Core/Extensions/EnumerableExtensions.cs index 3d6ba7c9..4cd26aee 100644 --- a/zero.Core/Extensions/EnumerableExtensions.cs +++ b/zero.Core/Extensions/EnumerableExtensions.cs @@ -10,7 +10,7 @@ namespace zero.Core.Extensions /// /// /// - public static ListResult ToQueriedList(this IEnumerable items, ListQuery query) where T : IZeroEntity + public static ListResult ToQueriedList(this IEnumerable items, ListQuery query) where T : ZeroEntity { //queryable = queryable.Statistics(out QueryStatistics stats); diff --git a/zero.Core/Extensions/RavenQueryableExtensions.cs b/zero.Core/Extensions/RavenQueryableExtensions.cs index 9cce05a6..375d1059 100644 --- a/zero.Core/Extensions/RavenQueryableExtensions.cs +++ b/zero.Core/Extensions/RavenQueryableExtensions.cs @@ -1,11 +1,9 @@ using Raven.Client.Documents; using Raven.Client.Documents.Linq; using Raven.Client.Documents.Session; -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using zero.Core.Api; using zero.Core.Entities; namespace zero.Core.Extensions @@ -13,7 +11,7 @@ namespace zero.Core.Extensions public static class RavenQueryableExtensions { // TODO we need to simplify these extensions methods. - // ToQueriedListAsyncX is used in MediaCollection for the Media_ByParent index, which produces MediaListItem (which is no IZeroEntity) + // ToQueriedListAsyncX is used in MediaCollection for the Media_ByParent index, which produces MediaListItem (which is no ZeroEntity) /// /// /// @@ -61,7 +59,7 @@ namespace zero.Core.Extensions /// /// /// - public static async Task> ToQueriedListAsync(this IRavenQueryable queryable, ListQuery query) where T : IZeroEntity + public static async Task> ToQueriedListAsync(this IRavenQueryable queryable, ListQuery query) where T : ZeroEntity { queryable = queryable.Statistics(out QueryStatistics stats); @@ -150,7 +148,7 @@ namespace zero.Core.Extensions /// /// /// - public static async Task> ToQueriedListAsync(this IRavenQueryable queryable, ListQuery query) where T : IZeroEntity where TFilter : IListSpecificQuery + public static async Task> ToQueriedListAsync(this IRavenQueryable queryable, ListQuery query) where T : ZeroEntity where TFilter : IListSpecificQuery { queryable = queryable.Statistics(out QueryStatistics stats); diff --git a/zero.Core/Extensions/ValidatorExtensions.cs b/zero.Core/Extensions/ValidatorExtensions.cs index 82b8f99b..cdaa88c6 100644 --- a/zero.Core/Extensions/ValidatorExtensions.cs +++ b/zero.Core/Extensions/ValidatorExtensions.cs @@ -101,14 +101,14 @@ namespace zero.Core.Extensions /// /// Check if this value is unique within a collection /// - public static IRuleBuilderOptions Unique(this IRuleBuilder ruleBuilder, IBackofficeStore store) where T : IZeroEntity + public static IRuleBuilderOptions Unique(this IRuleBuilder ruleBuilder, IBackofficeStore store) where T : ZeroEntity { return ruleBuilder.MustAsync(async (entity, value, context, cancellation) => { using IAsyncDocumentSession session = store.Store.OpenAsyncSession(); bool any = await session.Advanced.AsyncDocumentQuery() - .WhereNotEquals(nameof(IZeroIdEntity.Id), entity.Id) + .WhereNotEquals(nameof(ZeroIdEntity.Id), entity.Id) .WhereEquals(context.Rule.PropertyName.ToPascalCaseId(), value) .AnyAsync(cancellation); @@ -120,14 +120,14 @@ namespace zero.Core.Extensions /// /// Check if this value is at least set once to the expected value within a collection /// - public static IRuleBuilderOptions ExpectAnyUnique(this IRuleBuilder ruleBuilder, IBackofficeStore store, TProperty expectedValue) where T : IZeroEntity + public static IRuleBuilderOptions ExpectAnyUnique(this IRuleBuilder ruleBuilder, IBackofficeStore store, TProperty expectedValue) where T : ZeroEntity { return ruleBuilder.MustAsync(async (entity, value, context, cancellation) => { using IAsyncDocumentSession session = store.Store.OpenAsyncSession(); return await session.Advanced.AsyncDocumentQuery() - .WhereNotEquals(nameof(IZeroIdEntity.Id), entity.Id) + .WhereNotEquals(nameof(ZeroIdEntity.Id), entity.Id) .WhereEquals(context.Rule.PropertyName.ToPascalCaseId(), expectedValue) .AnyAsync(cancellation); }).WithMessage("@errors.forms.not_unique_alone"); @@ -137,7 +137,7 @@ namespace zero.Core.Extensions /// /// Check if this reference exists and is an entity which can be referenced (appId = shared for shareable entities or appId = current) /// - public static IRuleBuilderOptions Exists(this IRuleBuilder ruleBuilder, IBackofficeStore store) where T : IZeroEntity + public static IRuleBuilderOptions Exists(this IRuleBuilder ruleBuilder, IBackofficeStore store) where T : ZeroEntity { return ruleBuilder.Exists(store); } @@ -146,7 +146,7 @@ namespace zero.Core.Extensions /// /// Check if this reference exists and is an entity which can be referenced (appId = shared for shareable entities or appId = current) /// - public static IRuleBuilderOptions Exists(this IRuleBuilder ruleBuilder, IBackofficeStore store) where T : IZeroEntity where TReference : IZeroEntity + public static IRuleBuilderOptions Exists(this IRuleBuilder ruleBuilder, IBackofficeStore store) where T : ZeroEntity where TReference : ZeroEntity { return ruleBuilder.MustAsync(async (entity, id, context, cancellation) => { diff --git a/zero.Core/Handlers/IApplicationResolverHandler.cs b/zero.Core/Handlers/IApplicationResolverHandler.cs index 08e94b39..f7dc1e98 100644 --- a/zero.Core/Handlers/IApplicationResolverHandler.cs +++ b/zero.Core/Handlers/IApplicationResolverHandler.cs @@ -10,6 +10,6 @@ namespace zero.Core.Handlers { public interface IApplicationResolverHandler : IHandler { - IApplication Resolve(HttpRequest request, IList applications); + Application Resolve(HttpRequest request, IList applications); } } diff --git a/zero.Core/Handlers/IModuleTypeHandler.cs b/zero.Core/Handlers/IModuleTypeHandler.cs index 76759f6d..9c995b46 100644 --- a/zero.Core/Handlers/IModuleTypeHandler.cs +++ b/zero.Core/Handlers/IModuleTypeHandler.cs @@ -5,6 +5,6 @@ namespace zero.Core.Handlers { public interface IModuleTypeHandler : IHandler { - IEnumerable GetAllowedModuleTypes(IApplication application, IEnumerable registeredTypes, IPage page = default, string[] tags = default); + IEnumerable GetAllowedModuleTypes(Application application, IEnumerable registeredTypes, Page page = default, string[] tags = default); } } diff --git a/zero.Core/Handlers/IPageTypeHandler.cs b/zero.Core/Handlers/IPageTypeHandler.cs index d5819332..5ab1dc90 100644 --- a/zero.Core/Handlers/IPageTypeHandler.cs +++ b/zero.Core/Handlers/IPageTypeHandler.cs @@ -7,6 +7,6 @@ namespace zero.Core.Handlers { public interface IPageTypeHandler : IHandler { - IEnumerable GetAllowedPageTypes(IApplication application, IEnumerable registeredTypes, IEnumerable parents); + IEnumerable GetAllowedPageTypes(Application application, IEnumerable registeredTypes, IEnumerable parents); } } diff --git a/zero.Core/Identity/IIdentityUserRole.cs b/zero.Core/Identity/IIdentityUserRole.cs deleted file mode 100644 index 5bdd43cd..00000000 --- a/zero.Core/Identity/IIdentityUserRole.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; -using zero.Core.Entities; - -namespace zero.Core.Identity -{ - public interface IIdentityUserRole : IZeroEntity - { - /// - /// The user's claims, for use in claims-based authentication. - /// - List Claims { get; set; } - } -} diff --git a/zero.Core/Identity/RavenRoleStore(TRole).cs b/zero.Core/Identity/RavenRoleStore(TRole).cs index d50b9d58..c21ffc65 100644 --- a/zero.Core/Identity/RavenRoleStore(TRole).cs +++ b/zero.Core/Identity/RavenRoleStore(TRole).cs @@ -15,7 +15,7 @@ using zero.Core.Options; namespace zero.Core.Identity { public class RavenRoleStore : IRoleStore, IRoleClaimStore - where TRole : class, IIdentityUserRole + where TRole : ZeroIdentityRole { protected IZeroStore Store { get; private set; } diff --git a/zero.Core/Identity/RavenScopedStores.cs b/zero.Core/Identity/RavenScopedStores.cs index 0900e0ae..f43ebffc 100644 --- a/zero.Core/Identity/RavenScopedStores.cs +++ b/zero.Core/Identity/RavenScopedStores.cs @@ -1,11 +1,12 @@ using Microsoft.AspNetCore.Identity; using zero.Core.Database; +using zero.Core.Entities; using zero.Core.Options; namespace zero.Core.Identity { public class RavenCoreRoleStore : RavenRoleStore - where TRole : class, IIdentityUserRole + where TRole : ZeroIdentityRole { public RavenCoreRoleStore(IZeroStore store, IZeroOptions options, IdentityErrorDescriber describer = null) : base(store, options, describer) { } @@ -16,7 +17,7 @@ namespace zero.Core.Identity public class RavenCoreUserStore : RavenUserStore - where TUser : class, IIdentityUser + where TUser : ZeroIdentityUser { public RavenCoreUserStore(IZeroStore store, IZeroOptions options) : base(store, options) { } @@ -27,8 +28,8 @@ namespace zero.Core.Identity public class RavenCoreUserStore : RavenUserStore - where TUser : class, IIdentityUserWithRoles - where TRole : class, IIdentityUserRole + where TUser : ZeroIdentityUser + where TRole : ZeroIdentityRole { public RavenCoreUserStore(IZeroStore store, IZeroOptions options) : base(store, options) { } diff --git a/zero.Core/Identity/RavenUserStore(TUser).cs b/zero.Core/Identity/RavenUserStore(TUser).cs index e0b73b7b..e247ea2b 100644 --- a/zero.Core/Identity/RavenUserStore(TUser).cs +++ b/zero.Core/Identity/RavenUserStore(TUser).cs @@ -23,7 +23,7 @@ namespace zero.Core.Identity IUserClaimStore, IUserSecurityStampStore, IProtectedUserStore - where TUser : class, IIdentityUser + where TUser : ZeroIdentityUser { protected IZeroStore Store { get; private set; } diff --git a/zero.Core/Identity/RavenUserStore(TUser,TRole).cs b/zero.Core/Identity/RavenUserStore(TUser,TRole).cs index bfd038f9..1f376103 100644 --- a/zero.Core/Identity/RavenUserStore(TUser,TRole).cs +++ b/zero.Core/Identity/RavenUserStore(TUser,TRole).cs @@ -8,6 +8,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using zero.Core.Database; +using zero.Core.Entities; using zero.Core.Options; namespace zero.Core.Identity @@ -17,8 +18,8 @@ namespace zero.Core.Identity public partial class RavenUserStore : RavenUserStore, IUserRoleStore - where TUser : class, IIdentityUserWithRoles - where TRole : class, IIdentityUserRole + where TUser : ZeroIdentityUser + where TRole : ZeroIdentityRole { public RavenUserStore(IZeroStore store, IZeroOptions options) : base(store, options) { } diff --git a/zero.Core/Identity/ZeroIdentityExtensions.cs b/zero.Core/Identity/ZeroIdentityExtensions.cs index b00611a0..de143aa5 100644 --- a/zero.Core/Identity/ZeroIdentityExtensions.cs +++ b/zero.Core/Identity/ZeroIdentityExtensions.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using System; +using zero.Core.Entities; using zero.Core.Security; namespace zero.Core.Identity @@ -9,8 +10,8 @@ namespace zero.Core.Identity public static class ZeroIdentityExtensions { public static IdentityBuilder AddZeroIdentity(this IServiceCollection services) - where TUser : class, IIdentityUserWithRoles, IIdentityUser - where TRole : class, IIdentityUserRole + where TUser : ZeroIdentityUser + where TRole : ZeroIdentityRole { services.AddZeroIdentityCore(); @@ -31,7 +32,7 @@ namespace zero.Core.Identity public static IdentityBuilder AddZeroIdentity(this IServiceCollection services) - where TUser : class, IIdentityUser + where TUser : ZeroIdentityUser { services.AddZeroIdentityCore(); @@ -47,7 +48,7 @@ namespace zero.Core.Identity static IServiceCollection AddZeroIdentityCore(this IServiceCollection services) - where TUser : class, IIdentityUser + where TUser : ZeroIdentityUser { services.AddHttpContextAccessor(); services.AddOptions(); @@ -85,7 +86,7 @@ namespace zero.Core.Identity services.Configure(opts => { - opts.ValidationInterval = TimeSpan.FromMinutes(30); + opts.ValidationInterval = TimeSpan.FromMinutes(90); }); return services; diff --git a/zero.Core/Integrations/Integration.cs b/zero.Core/Integrations/Integration.cs index a683b73b..df9b7e23 100644 --- a/zero.Core/Integrations/Integration.cs +++ b/zero.Core/Integrations/Integration.cs @@ -4,18 +4,14 @@ using zero.Core.Entities; namespace zero.Core.Integrations { - /// - public class Integration : ZeroEntity, IIntegration - { - /// - public string TypeAlias { get; set; } - } - - /// /// An integration is an application part which has a public configuration per app. /// It's up to the user to provide functionality. /// [Collection("Integrations")] - public interface IIntegration : IZeroConfigEntity, IZeroDbConventions { } + public class Integration : ZeroEntity + { + /// + public string TypeAlias { get; set; } + } } \ No newline at end of file diff --git a/zero.Core/Mails/Mail.cs b/zero.Core/Mails/Mail.cs index 619a14bb..1745f53b 100644 --- a/zero.Core/Mails/Mail.cs +++ b/zero.Core/Mails/Mail.cs @@ -19,7 +19,7 @@ namespace zero.Core.Mails public string Preheader { get; set; } - public IMailTemplate Template { get; set; } + public MailTemplate Template { get; set; } public MailPlaceholders Placeholders { get; set; } = new(); diff --git a/zero.Core/Mails/MailProvider.cs b/zero.Core/Mails/MailProvider.cs index 1864c784..5ad16872 100644 --- a/zero.Core/Mails/MailProvider.cs +++ b/zero.Core/Mails/MailProvider.cs @@ -43,7 +43,7 @@ namespace zero.Core.Mails /// public virtual async Task Create(string mailTemplateKey, CancellationToken token = default) where T : Mail, new() { - IMailTemplate template = await GetMailTemplate(mailTemplateKey); + MailTemplate template = await GetMailTemplate(mailTemplateKey); if (template == null) { @@ -58,7 +58,7 @@ namespace zero.Core.Mails /// public virtual async Task Create(string mailTemplateKey, CancellationToken token = default) { - IMailTemplate template = await GetMailTemplate(mailTemplateKey); + MailTemplate template = await GetMailTemplate(mailTemplateKey); if (template == null) { @@ -95,7 +95,7 @@ namespace zero.Core.Mails - protected virtual async Task GetMailTemplate(string key) + protected virtual async Task GetMailTemplate(string key) { return await Collection.GetByKey(key); } @@ -128,7 +128,7 @@ namespace zero.Core.Mails } - protected virtual T Merge(T mail, IMailTemplate template) where T : Mail + protected virtual T Merge(T mail, MailTemplate template) where T : Mail { mail.Template = template; diff --git a/zero.Core/Options/FeatureOptions.cs b/zero.Core/Options/FeatureOptions.cs index 4b5bab9b..e901c337 100644 --- a/zero.Core/Options/FeatureOptions.cs +++ b/zero.Core/Options/FeatureOptions.cs @@ -2,9 +2,9 @@ namespace zero.Core.Options { - public class FeatureOptions : ZeroBackofficeCollection, IZeroCollectionOptions + public class FeatureOptions : ZeroBackofficeCollection, IZeroCollectionOptions { - public void Add() where T : IFeature, new() + public void Add() where T : Feature, new() { Items.Add(new T()); } diff --git a/zero.Core/Options/IconOptions.cs b/zero.Core/Options/IconOptions.cs index 1d779c00..c0fcb6bb 100644 --- a/zero.Core/Options/IconOptions.cs +++ b/zero.Core/Options/IconOptions.cs @@ -2,7 +2,7 @@ namespace zero.Core.Options { - public class IconOptions : ZeroBackofficeCollection, IZeroCollectionOptions + public class IconOptions : ZeroBackofficeCollection, IZeroCollectionOptions { /// /// Add a new backoffice icon set diff --git a/zero.Core/Options/RoutingPageResolverOptions.cs b/zero.Core/Options/RoutingPageResolverOptions.cs index cc084f6e..11934dda 100644 --- a/zero.Core/Options/RoutingPageResolverOptions.cs +++ b/zero.Core/Options/RoutingPageResolverOptions.cs @@ -13,11 +13,11 @@ namespace zero.Core.Options class ResolverMap { public Type Type { get; set; } - public Expression> Impl { get; set; } + public Expression> Impl { get; set; } } - public void Add(Expression> resolver) + public void Add(Expression> resolver) { Resolvers.Add(new() { @@ -26,7 +26,7 @@ namespace zero.Core.Options }); } - public void Replace(Expression> resolver) + public void Replace(Expression> resolver) { Remove(); Add(resolver); @@ -38,17 +38,17 @@ namespace zero.Core.Options Resolvers.RemoveWhere(x => x.Type == type); } - public Expression> Get() => Get(typeof(T)); + public Expression> Get() => Get(typeof(T)); - public IEnumerable>> GetAll() => GetAll(typeof(T)); + public IEnumerable>> GetAll() => GetAll(typeof(T)); - public Expression> Get(Type type) + public Expression> Get(Type type) { ResolverMap map = Resolvers.LastOrDefault(x => x.Type == type); return map?.Impl; } - public IEnumerable>> GetAll(Type type) + public IEnumerable>> GetAll(Type type) { IEnumerable maps = Resolvers.Where(x => x.Type == type); return maps.Select(map => map.Impl).Where(x => x != null); diff --git a/zero.Core/Routing/AbtractRouteProvider.cs b/zero.Core/Routing/AbtractRouteProvider.cs index b916300a..c4f09587 100644 --- a/zero.Core/Routing/AbtractRouteProvider.cs +++ b/zero.Core/Routing/AbtractRouteProvider.cs @@ -54,9 +54,9 @@ namespace zero.Core.Routing /// - public virtual async Task> GetRoutes(IAsyncDocumentSession session, IEnumerable models, object parameters = null) + public virtual async Task> GetRoutes(IAsyncDocumentSession session, IEnumerable models, object parameters = null) { - Dictionary result = new(); + Dictionary result = new(); Dictionary routeMap = new(); HashSet routeIds = new(); @@ -67,9 +67,9 @@ namespace zero.Core.Routing routeMap.TryAdd(routeId, model); } - Dictionary routes = await session.LoadAsync(routeIds); + Dictionary routes = await session.LoadAsync(routeIds); - foreach ((string key, IRoute route) in routes) + foreach ((string key, Route route) in routes) { if (routeMap.TryGetValue(key, out T model)) { @@ -82,21 +82,21 @@ namespace zero.Core.Routing /// - public virtual async Task> GetRoutes(IAsyncDocumentSession session, IEnumerable models, object parameters = null) + public virtual async Task> GetRoutes(IAsyncDocumentSession session, IEnumerable models, object parameters = null) { return (await GetRoutes(session, models.Select(x => (T)x).ToArray(), parameters)).ToDictionary(x => (object)x.Key, x => x.Value); } /// - public virtual async Task GetRoute(IAsyncDocumentSession session, T model, object parameters = null) + public virtual async Task GetRoute(IAsyncDocumentSession session, T model, object parameters = null) { - return await session.LoadAsync(GetRouteId(model, parameters)); + return await session.LoadAsync(GetRouteId(model, parameters)); } /// - public virtual async Task GetRoute(IAsyncDocumentSession session, object model, object parameters = null) + public virtual async Task GetRoute(IAsyncDocumentSession session, object model, object parameters = null) { if (!(model is T)) { @@ -107,7 +107,7 @@ namespace zero.Core.Routing /// - public virtual Task ResolveRoute(IAsyncDocumentSession session, IRoute route) + public virtual Task ResolveRoute(IAsyncDocumentSession session, Route route) { DefaultResolvedRoute resolved = new DefaultResolvedRoute() { Route = route }; return Task.FromResult((IResolvedRoute)resolved); @@ -115,7 +115,7 @@ namespace zero.Core.Routing /// - public abstract Task> GetAllRoutes(IAsyncDocumentSession session); + public abstract Task> GetAllRoutes(IAsyncDocumentSession session); /// @@ -134,13 +134,13 @@ namespace zero.Core.Routing } - protected async Task ResolvePage(IAsyncDocumentSession session) + protected async Task ResolvePage(IAsyncDocumentSession session) { - IEnumerable>> resolvers = Options.Routing.PageResolvers.GetAll(typeof(T)); + IEnumerable>> resolvers = Options.Routing.PageResolvers.GetAll(typeof(T)); - foreach (Expression> resolver in resolvers.Reverse()) + foreach (Expression> resolver in resolvers.Reverse()) { - IPage page = await session.Query().FirstOrDefaultAsync(resolver); + Page page = await session.Query().FirstOrDefaultAsync(resolver); if (page != null) { @@ -152,38 +152,38 @@ namespace zero.Core.Routing } - protected async Task> ResolvePages(IAsyncDocumentSession session) + protected async Task> ResolvePages(IAsyncDocumentSession session) { - List pages = new(); - IEnumerable>> resolvers = Options.Routing.PageResolvers.GetAll(typeof(T)); + List pages = new(); + IEnumerable>> resolvers = Options.Routing.PageResolvers.GetAll(typeof(T)); - foreach (Expression> resolver in resolvers.Reverse()) + foreach (Expression> resolver in resolvers.Reverse()) { - pages.AddRange(await session.Query().Where(resolver).ToListAsync()); + pages.AddRange(await session.Query().Where(resolver).ToListAsync()); } return pages; } - protected async Task ResolvePageRoute(IAsyncDocumentSession session) + protected async Task ResolvePageRoute(IAsyncDocumentSession session) { - IPage page = await ResolvePage(session); + Page page = await ResolvePage(session); // WARNING: we are assuming that the route id is built from the page hash but this could be altered with PageRouteProvier.GetRouteId. // we cannot use a dependency on this provider here as we are working from the abstract route provider which is the base of the PageRouteProvider itself, // and therefore a circular dependency. - return page == null ? null : await session.LoadAsync(ID_PREFIX + page.Hash); + return page == null ? null : await session.LoadAsync(ID_PREFIX + page.Hash); } - protected async Task> ResolvePageRoutes(IAsyncDocumentSession session) + protected async Task> ResolvePageRoutes(IAsyncDocumentSession session) { - List routes = new(); - IEnumerable pages = await ResolvePages(session); + List routes = new(); + IEnumerable pages = await ResolvePages(session); string[] ids = pages.Select(x => ID_PREFIX + x.Hash).ToArray(); - return ids.Length < 1 ? routes : (await session.LoadAsync(ids)).Select(x => x.Value); + return ids.Length < 1 ? routes : (await session.LoadAsync(ids)).Select(x => x.Value); } } } diff --git a/zero.Core/Routing/DefaultResolvedRoute.cs b/zero.Core/Routing/DefaultResolvedRoute.cs index c459c3af..3824d626 100644 --- a/zero.Core/Routing/DefaultResolvedRoute.cs +++ b/zero.Core/Routing/DefaultResolvedRoute.cs @@ -2,6 +2,6 @@ { public class DefaultResolvedRoute : IResolvedRoute { - public IRoute Route { get; set; } + public Route Route { get; set; } } } diff --git a/zero.Core/Routing/ILinkProvider.cs b/zero.Core/Routing/ILinkProvider.cs index a8cfed73..67e38b6f 100644 --- a/zero.Core/Routing/ILinkProvider.cs +++ b/zero.Core/Routing/ILinkProvider.cs @@ -9,16 +9,16 @@ namespace zero.Core.Routing /// /// /// - bool CanProcess(ILink link); + bool CanProcess(Link link); /// /// /// - Task Resolve(ILink link); + Task Resolve(Link link); /// /// /// - Task Preview(IAsyncDocumentSession session, ILink link); + Task Preview(IAsyncDocumentSession session, Link link); } } diff --git a/zero.Core/Routing/IResolvedRoute.cs b/zero.Core/Routing/IResolvedRoute.cs index 19e4f207..5cc4402d 100644 --- a/zero.Core/Routing/IResolvedRoute.cs +++ b/zero.Core/Routing/IResolvedRoute.cs @@ -2,6 +2,6 @@ { public interface IResolvedRoute { - IRoute Route { get; set; } + Route Route { get; set; } } } diff --git a/zero.Core/Routing/IRouteProvider.cs b/zero.Core/Routing/IRouteProvider.cs index 38b746cf..bdf8cf4d 100644 --- a/zero.Core/Routing/IRouteProvider.cs +++ b/zero.Core/Routing/IRouteProvider.cs @@ -11,12 +11,12 @@ namespace zero.Core.Routing /// /// Find URL for an entity /// - Task GetRoute(IAsyncDocumentSession session, T model, object parameters = null); + Task GetRoute(IAsyncDocumentSession session, T model, object parameters = null); /// /// Find URLs for mulitple entities /// - Task> GetRoutes(IAsyncDocumentSession session, IEnumerable models, object parameters = null); + Task> GetRoutes(IAsyncDocumentSession session, IEnumerable models, object parameters = null); /// /// Generate unique route ID for a model @@ -40,22 +40,22 @@ namespace zero.Core.Routing /// Resolve a route and load optional dependencies into it. /// This is the data which is passed to the specified controller action. /// - Task ResolveRoute(IAsyncDocumentSession session, IRoute route); + Task ResolveRoute(IAsyncDocumentSession session, Route route); /// /// Find URL for an entity /// - Task GetRoute(IAsyncDocumentSession session, object model, object parameters = null); + Task GetRoute(IAsyncDocumentSession session, object model, object parameters = null); /// /// Find URLs for mulitple entities /// - Task> GetRoutes(IAsyncDocumentSession session, IEnumerable models, object parameters = null); + Task> GetRoutes(IAsyncDocumentSession session, IEnumerable models, object parameters = null); /// /// Rebuild all routes for this provider so they can be hydrated into the database /// - Task> GetAllRoutes(IAsyncDocumentSession session); + Task> GetAllRoutes(IAsyncDocumentSession session); /// /// Generate unique route ID for a model diff --git a/zero.Core/Routing/Links.cs b/zero.Core/Routing/Links.cs index 5132f82b..b0b76bdf 100644 --- a/zero.Core/Routing/Links.cs +++ b/zero.Core/Routing/Links.cs @@ -32,7 +32,7 @@ namespace zero.Core.Routing /// - public async Task GetUrl(ILink link) + public async Task GetUrl(Link link) { ILinkProvider provider = Providers.LastOrDefault(x => x.CanProcess(link)); @@ -47,11 +47,11 @@ namespace zero.Core.Routing /// - public async Task> GetUrls(params ILink[] links) + public async Task> GetUrls(params Link[] links) { - Dictionary result = new(); + Dictionary result = new(); - foreach (ILink link in links) + foreach (Link link in links) { result.Add(link, await GetUrl(link)); } @@ -61,7 +61,7 @@ namespace zero.Core.Routing /// - public ILinkProvider GetProvider(ILink link) + public ILinkProvider GetProvider(Link link) { return Providers.LastOrDefault(x => x.CanProcess(link)); } @@ -72,17 +72,17 @@ namespace zero.Core.Routing /// /// Get URL from a link object by finding a provider which can resolve the link /// - Task GetUrl(ILink link); + Task GetUrl(Link link); /// /// Get URLs from link objects by finding matching providers /// - Task> GetUrls(params ILink[] links); + Task> GetUrls(params Link[] links); /// /// Get the provider for a specific link /// - ILinkProvider GetProvider(ILink link); + ILinkProvider GetProvider(Link link); /// /// Find a provider by a specific type diff --git a/zero.Core/Routing/Page/BasePageRoute.cs b/zero.Core/Routing/Page/BasePageRoute.cs index fbeb28f7..fc4d28fa 100644 --- a/zero.Core/Routing/Page/BasePageRoute.cs +++ b/zero.Core/Routing/Page/BasePageRoute.cs @@ -7,13 +7,13 @@ namespace zero.Core.Routing { public BasePageRoute() { } - public BasePageRoute(IRoute route) + public BasePageRoute(Route route) { Route = route; } - public IPage Page { get; set; } + public Page Page { get; set; } - public IRoute Route { get; set; } + public Route Route { get; set; } } } diff --git a/zero.Core/Routing/Page/IPageUrlBuilder.cs b/zero.Core/Routing/Page/IPageUrlBuilder.cs index ac6afbee..8c9a573e 100644 --- a/zero.Core/Routing/Page/IPageUrlBuilder.cs +++ b/zero.Core/Routing/Page/IPageUrlBuilder.cs @@ -13,11 +13,11 @@ namespace zero.Core.Routing /// /// Get URL for a page /// - Task GetUrl(IPage page); + Task GetUrl(Page page); /// /// Get URL for a page /// - string GetUrl(IPage page, IEnumerable parents); + string GetUrl(Page page, IEnumerable parents); } } diff --git a/zero.Core/Routing/Page/PageLinkProvider.cs b/zero.Core/Routing/Page/PageLinkProvider.cs index 4da08739..a74002df 100644 --- a/zero.Core/Routing/Page/PageLinkProvider.cs +++ b/zero.Core/Routing/Page/PageLinkProvider.cs @@ -26,7 +26,7 @@ namespace zero.Core.Routing /// /// Creates a new link object from a page /// - public ILink Create(IPage page, LinkTarget target = LinkTarget.Default, string title = null) + public Link Create(Page page, LinkTarget target = LinkTarget.Default, string title = null) { return new Link() { @@ -42,19 +42,19 @@ namespace zero.Core.Routing /// - public bool CanProcess(ILink link) => link.Area == AREA; + public bool CanProcess(Link link) => link.Area == AREA; /// - public async Task Resolve(ILink link) + public async Task Resolve(Link link) { - link.Url = await Routes.GetUrl(link.Values.GetValueOrDefault("id")) + (link.UrlSuffix ?? string.Empty); + link.Url = await Routes.GetUrl(link.Values.GetValueOrDefault("id")) + (link.UrlSuffix ?? string.Empty); return link.Url; } /// - public async Task Preview(IAsyncDocumentSession session, ILink link) + public async Task Preview(IAsyncDocumentSession session, Link link) { string id = link.Values.GetValueOrDefault("id"); @@ -63,7 +63,7 @@ namespace zero.Core.Routing return null; } - IPage page = await session.LoadAsync(id); + Page page = await session.LoadAsync(id); if (page == null) { @@ -72,7 +72,7 @@ namespace zero.Core.Routing PageType pageType = Options.Pages.GetAllItems().FirstOrDefault(x => x.Alias == page.PageTypeAlias); - string url = await Routes.GetUrl(page); + string url = await Routes.GetUrl(page); return new() { diff --git a/zero.Core/Routing/Page/PageRoute.cs b/zero.Core/Routing/Page/PageRoute.cs index d6208911..aac3e1e2 100644 --- a/zero.Core/Routing/Page/PageRoute.cs +++ b/zero.Core/Routing/Page/PageRoute.cs @@ -6,8 +6,8 @@ namespace zero.Core.Routing public class PageRoute : BasePageRoute { public PageRoute() { } - public PageRoute(IRoute route) : base(route) { } + public PageRoute(Route route) : base(route) { } - public IList Parents { get; set; } + public IList Parents { get; set; } } } diff --git a/zero.Core/Routing/Page/PageRouteProvider.cs b/zero.Core/Routing/Page/PageRouteProvider.cs index 3f0f6896..93517dab 100644 --- a/zero.Core/Routing/Page/PageRouteProvider.cs +++ b/zero.Core/Routing/Page/PageRouteProvider.cs @@ -11,7 +11,7 @@ using zero.Core.Options; namespace zero.Core.Routing { - public class PageRouteProvider : AbtractRouteProvider + public class PageRouteProvider : AbtractRouteProvider { protected const string REF_KEY = "page"; protected const string PAGE_TYPE_KEY = "pageType"; @@ -29,11 +29,11 @@ namespace zero.Core.Routing /// - public override string GetRouteId(IPage model, object parameters = null) => ID_PREFIX + model.Hash; + public override string GetRouteId(Page model, object parameters = null) => ID_PREFIX + model.Hash; /// - public override async Task ResolveRoute(IAsyncDocumentSession session, IRoute route) + public override async Task ResolveRoute(IAsyncDocumentSession session, Route route) { PageRoute resolved = new PageRoute(route); @@ -48,9 +48,9 @@ namespace zero.Core.Routing ids.Add(reference.Id); ids.AddRange(route.Dependencies); - Dictionary pages = await session.LoadAsync(ids); + Dictionary pages = await session.LoadAsync(ids); - if (!pages.TryGetValue(reference.Id, out IPage page)) + if (!pages.TryGetValue(reference.Id, out Page page)) { return null; } @@ -63,44 +63,44 @@ namespace zero.Core.Routing /// - public override async Task> GetAllRoutes(IAsyncDocumentSession session) + public override async Task> GetAllRoutes(IAsyncDocumentSession session) { - IList TraversePageChildren(IPage parent, IEnumerable parents, IEnumerable allPages) + IList TraversePageChildren(Page parent, IEnumerable parents, IEnumerable allPages) { - List routes = new List(); - IEnumerable currentPages = allPages.Where(x => x.ParentId == parent?.Id); + List routes = new List(); + IEnumerable currentPages = allPages.Where(x => x.ParentId == parent?.Id); - foreach (IPage page in currentPages) + foreach (Page page in currentPages) { - IRoute route = BuildRoute(page, parents, allPages); + Route route = BuildRoute(page, parents, allPages); if (route != null) { routes.Add(route); } - routes.AddRange(TraversePageChildren(page, parents.Union(new List() { page }), allPages)); + routes.AddRange(TraversePageChildren(page, parents.Union(new List() { page }), allPages)); } return routes; } - IList pages = await session.Query().ToListAsync(); - return TraversePageChildren(null, new List() { }, pages); + IList pages = await session.Query().ToListAsync(); + return TraversePageChildren(null, new List() { }, pages); } /// /// Build route entity from page /// - protected virtual IRoute BuildRoute(IPage page, IEnumerable parents, IEnumerable allPages) + protected virtual Route BuildRoute(Page page, IEnumerable parents, IEnumerable allPages) { if (page is PageFolder) { return null; } - IRoute route = new Route() + Route route = new Route() { Id = GetRouteId(page), Url = UrlBuilder.GetUrl(page, parents), @@ -112,7 +112,7 @@ namespace zero.Core.Routing if (parents != null) { - foreach (IPage parent in parents) + foreach (Page parent in parents) { route.Dependencies.Add(parent.Id); } diff --git a/zero.Core/Routing/Page/PageUrlBuilder.cs b/zero.Core/Routing/Page/PageUrlBuilder.cs index ff27e7ff..c30f6f01 100644 --- a/zero.Core/Routing/Page/PageUrlBuilder.cs +++ b/zero.Core/Routing/Page/PageUrlBuilder.cs @@ -33,22 +33,22 @@ namespace zero.Core.Routing /// - public async Task GetUrl(IPage page) + public async Task GetUrl(Page page) { using IAsyncDocumentSession session = Store.OpenAsyncSession(); Pages_ByHierarchy.Result result = await session.Query() .ProjectInto() - .Include(x => x.Path.Select(p => p.Id)) + .Include(x => x.Path.Select(p => p.Id)) .FirstOrDefaultAsync(x => x.Id == page.Id); - IList parents = (await session.LoadAsync(result.Path.Select(x => x.Id))).Select(x => x.Value).ToList(); + IList parents = (await session.LoadAsync(result.Path.Select(x => x.Id))).Select(x => x.Value).ToList(); StringBuilder stringBuilder = new StringBuilder(); if (parents != null) { - foreach (IPage parent in parents) + foreach (Page parent in parents) { stringBuilder.Append(GetUrlPart(parent)); stringBuilder.Append(PATH_SEPARATOR); @@ -68,12 +68,12 @@ namespace zero.Core.Routing /// - public string GetUrl(IPage page, IEnumerable parents) + public string GetUrl(Page page, IEnumerable parents) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(PATH_SEPARATOR); - void AddPart(IPage page) + void AddPart(Page page) { string part = GetUrlPart(page); @@ -86,7 +86,7 @@ namespace zero.Core.Routing if (parents != null) { - foreach (IPage parent in parents) + foreach (Page parent in parents) { AddPart(parent); } @@ -106,7 +106,7 @@ namespace zero.Core.Routing /// /// Get the part of the URL (by querying UrlAlias and Alias) for this page /// - protected virtual string GetUrlPart(IPage page) + protected virtual string GetUrlPart(Page page) { string alias; diff --git a/zero.Core/Routing/RawLinkProvider.cs b/zero.Core/Routing/RawLinkProvider.cs index 23285349..cb4f297a 100644 --- a/zero.Core/Routing/RawLinkProvider.cs +++ b/zero.Core/Routing/RawLinkProvider.cs @@ -14,7 +14,7 @@ namespace zero.Core.Routing /// /// Creates a new link object from an url /// - public ILink Create(string url, LinkTarget target = LinkTarget.Default, string title = null) + public Link Create(string url, LinkTarget target = LinkTarget.Default, string title = null) { return new Link() { @@ -30,11 +30,11 @@ namespace zero.Core.Routing /// - public bool CanProcess(ILink link) => link.Area == AREA; + public bool CanProcess(Link link) => link.Area == AREA; /// - public Task Resolve(ILink link) + public Task Resolve(Link link) { link.Url = link.Values.GetValueOrDefault("url"); return Task.FromResult(link.Url); @@ -42,7 +42,7 @@ namespace zero.Core.Routing /// - public Task Preview(IAsyncDocumentSession session, ILink link) + public Task Preview(IAsyncDocumentSession session, Link link) { string url = link.Values.GetValueOrDefault("url"); diff --git a/zero.Core/Routing/Route.cs b/zero.Core/Routing/Route.cs index fe61f6ba..6dac8050 100644 --- a/zero.Core/Routing/Route.cs +++ b/zero.Core/Routing/Route.cs @@ -5,28 +5,37 @@ using zero.Core.Entities; namespace zero.Core.Routing { [Collection("Routes")] - public class Route : IRoute + public class Route : ZeroIdEntity { - /// - public string Id { get; set; } - - /// + /// + /// Generated URL based on the URL provider + /// public string Url { get; set; } - /// + /// + /// Alias of the URL provider which generated this route + /// public string ProviderAlias { get; set; } - /// + /// + /// Enable this property so all routes are catched which start with this Url + /// public bool AllowSuffix { get; set; } - /// - public Dictionary Params { get; set; } = new Dictionary(); + /// + /// Additional parameters + /// + public Dictionary Params { get; set; } = new(); - /// - public IList References { get; set; } = new List(); + /// + /// Contains references to the resolved collection entities + /// + public List References { get; set; } = new(); - /// - public IList Dependencies { get; set; } = new List(); + /// + /// Route dependencies can be used for cache busting + /// + public List Dependencies { get; set; } = new(); } @@ -44,39 +53,4 @@ namespace zero.Core.Routing Collection = collection; } } - - - [Collection("Routes")] - public interface IRoute : IZeroIdEntity, IZeroDbConventions - { - /// - /// Generated URL based on the URL provider - /// - string Url { get; set; } - - /// - /// Alias of the URL provider which generated this route - /// - string ProviderAlias { get; set; } - - /// - /// Enable this property so all routes are catched which start with this Url - /// - public bool AllowSuffix { get; set; } - - /// - /// Additional parameters - /// - Dictionary Params { get; set; } - - /// - /// Contains references to the resolved collection entities - /// - IList References { get; set; } - - /// - /// Route dependencies can be used for cache busting - /// - IList Dependencies { get; set; } - } } diff --git a/zero.Core/Routing/Routes.cs b/zero.Core/Routing/Routes.cs index fe4ebc86..65ed7bcf 100644 --- a/zero.Core/Routing/Routes.cs +++ b/zero.Core/Routing/Routes.cs @@ -41,7 +41,7 @@ namespace zero.Core.Routing /// - public async Task GetUrl(string id, object parameters = null) where T : IZeroIdEntity => (await GetRoute(id, parameters))?.Url; + public async Task GetUrl(string id, object parameters = null) where T : ZeroIdEntity => (await GetRoute(id, parameters))?.Url; /// @@ -49,7 +49,7 @@ namespace zero.Core.Routing /// - public async Task GetRoute(string id, object parameters = null) where T : IZeroIdEntity + public async Task GetRoute(string id, object parameters = null) where T : ZeroIdEntity { if (id.IsNullOrEmpty()) { @@ -77,7 +77,7 @@ namespace zero.Core.Routing /// - public async Task GetRoute(T model, object parameters = null) + public async Task GetRoute(T model, object parameters = null) { if (model == null) { @@ -98,7 +98,7 @@ namespace zero.Core.Routing /// - public async Task> GetRoutes(IEnumerable models, object parameters = null) + public async Task> GetRoutes(IEnumerable models, object parameters = null) { if (!models.Any()) { @@ -119,7 +119,7 @@ namespace zero.Core.Routing /// - public async Task ResolveUrl(IApplication application, string path) + public async Task ResolveUrl(Application application, string path) { path = path.Length > 1 ? path.TrimEnd(PATH_SEPERATOR) : path; @@ -138,13 +138,13 @@ namespace zero.Core.Routing min -= 1; } - IList routes = await session.Query() + IList routes = await session.Query() .Where(x => (!x.AllowSuffix && x.Url == path) || (x.AllowSuffix && x.Url.In(parts))) .Include("References[].Id") .Include("Dependencies") .ToListAsync(); - IRoute route = routes.FirstOrDefault(); + Route route = routes.FirstOrDefault(); // try to get the best matching path when multiple routes are found // our assumption is that the best path is those with the longest path parts separated by a slash @@ -152,7 +152,7 @@ namespace zero.Core.Routing if (routes.Count > 1) { int maxPathParts = routes.Max(x => x.Url.Count(u => u == PATH_SEPERATOR)); - IEnumerable longestRoutes = routes.Where(x => maxPathParts == x.Url.Count(u => u == PATH_SEPERATOR)).OrderBy(x => x.AllowSuffix); + IEnumerable longestRoutes = routes.Where(x => maxPathParts == x.Url.Count(u => u == PATH_SEPERATOR)).OrderBy(x => x.AllowSuffix); if (longestRoutes.Count() > 1) { @@ -179,7 +179,7 @@ namespace zero.Core.Routing return null; } - IApplication app = await AppResolver.ResolveFromRequest(context); + Application app = await AppResolver.ResolveFromRequest(context); string path = context.Request.Path; if (app == null) @@ -192,7 +192,7 @@ namespace zero.Core.Routing /// - public async Task ResolveRoute(IRoute route) + public async Task ResolveRoute(Route route) { using IAsyncDocumentSession session = Store.OpenAsyncSession(); return await ResolveRouteInternal(session, route); @@ -205,9 +205,9 @@ namespace zero.Core.Routing int count = 0; using IAsyncDocumentSession coreSession = Store.OpenCoreSession(); - List apps = await coreSession.Query().ToListAsync(); + List apps = await coreSession.Query().ToListAsync(); - foreach (IApplication app in apps) + foreach (Application app in apps) { using IAsyncDocumentSession session = Store.OpenAsyncSession(app.Database); session.Advanced.MaxNumberOfRequestsPerSession = 1000; @@ -215,10 +215,10 @@ namespace zero.Core.Routing foreach (IRouteProvider provider in Providers) { // get all routes for this provider - IList routes = await provider.GetAllRoutes(session); + IList routes = await provider.GetAllRoutes(session); // delete all registered routes in the database for this provider - await Store.PurgeAsync(app.Database, $"where {nameof(IRoute.ProviderAlias)} = $alias", new Raven.Client.Parameters() + await Store.PurgeAsync(app.Database, $"where {nameof(Route.ProviderAlias)} = $alias", new Raven.Client.Parameters() { { "alias", provider.Alias } }); @@ -226,7 +226,7 @@ namespace zero.Core.Routing // store new routes using (BulkInsertOperation bulkInsert = Store.BulkInsert(app.Database)) { - foreach (IRoute route in routes) + foreach (Route route in routes) { await bulkInsert.StoreAsync(route, route.Id); count += 1; @@ -248,7 +248,7 @@ namespace zero.Core.Routing /// /// Call the provider which can resolve the route /// - async Task ResolveRouteInternal(IAsyncDocumentSession session, IRoute route) + async Task ResolveRouteInternal(IAsyncDocumentSession session, Route route) { IRouteProvider routeProvider = FindProvider(route.ProviderAlias); return await routeProvider?.ResolveRoute(session, route); @@ -282,17 +282,17 @@ namespace zero.Core.Routing /// /// Get the URL for an entity /// - Task GetUrl(string id, object parameters = null) where T : IZeroIdEntity; + Task GetUrl(string id, object parameters = null) where T : ZeroIdEntity; /// /// Get the route object for an entity /// - Task GetRoute(T model, object parameters = null); + Task GetRoute(T model, object parameters = null); /// /// Get the route object for an entity /// - Task GetRoute(string id, object parameters = null) where T : IZeroIdEntity; + Task GetRoute(string id, object parameters = null) where T : ZeroIdEntity; /// /// Get URLs for multiple entities @@ -302,12 +302,12 @@ namespace zero.Core.Routing /// /// Get routes for multiple entities /// - Task> GetRoutes(IEnumerable models, object parameters = null); + Task> GetRoutes(IEnumerable models, object parameters = null); /// /// Resolve an URL from the specified app and the path /// - Task ResolveUrl(IApplication application, string path); + Task ResolveUrl(Application application, string path); /// /// Resolve an URL from an http context @@ -317,7 +317,7 @@ namespace zero.Core.Routing /// /// Resolve a route object by passing it to the specified provider /// - Task ResolveRoute(IRoute route); + Task ResolveRoute(Route route); /// /// Purges all routes and rebuilds them by iterating over all registered providers diff --git a/zero.Core/Security/SchemedSignInManager.cs b/zero.Core/Security/SchemedSignInManager.cs index 23c58eab..4e1a94fe 100644 --- a/zero.Core/Security/SchemedSignInManager.cs +++ b/zero.Core/Security/SchemedSignInManager.cs @@ -17,7 +17,7 @@ namespace zero.Core.Security // the authentication breaks when another application signs in a user // they share one cookie on both sites/applications, maybe this is an issue - public class SchemedSignInManager : SignInManager where TUser : class, IIdentityUser + public class SchemedSignInManager : SignInManager where TUser : ZeroIdentityUser { protected ZeroAuthOptions AuthOptions { get; private set; } diff --git a/zero.Core/Security/ZeroAuthOptions.cs b/zero.Core/Security/ZeroAuthOptions.cs index 99d41df8..783102ca 100644 --- a/zero.Core/Security/ZeroAuthOptions.cs +++ b/zero.Core/Security/ZeroAuthOptions.cs @@ -1,8 +1,8 @@ -using zero.Core.Identity; +using zero.Core.Entities; namespace zero.Core.Security { - public class ZeroAuthOptions where TUser : IIdentityUser + public class ZeroAuthOptions where TUser : ZeroIdentityUser { public string Scheme { get; set; } diff --git a/zero.Core/Security/ZeroBackofficeClaimsPrincipalFactory.cs b/zero.Core/Security/ZeroBackofficeClaimsPrincipalFactory.cs index 1c2f19a3..a479b7cb 100644 --- a/zero.Core/Security/ZeroBackofficeClaimsPrincipalFactory.cs +++ b/zero.Core/Security/ZeroBackofficeClaimsPrincipalFactory.cs @@ -11,8 +11,8 @@ using zero.Core.Identity; namespace zero.Core.Security { public class ZeroBackofficeClaimsPrincipalFactory : ZeroClaimsPrinicipalFactory - where TUser : class, IBackofficeUser - where TRole : class, IBackofficeUserRole + where TUser : BackofficeUser + where TRole : BackofficeUserRole { public ZeroBackofficeClaimsPrincipalFactory(UserManager userManager, RoleManager roleManager, IOptions optionsAccessor, IOptions> authOptions, IZeroContext zero) : base(userManager, roleManager, optionsAccessor, authOptions, zero) diff --git a/zero.Core/Security/ZeroClaimsPrinicipalFactory.cs b/zero.Core/Security/ZeroClaimsPrinicipalFactory.cs index 0e99d7c4..cd293cc1 100644 --- a/zero.Core/Security/ZeroClaimsPrinicipalFactory.cs +++ b/zero.Core/Security/ZeroClaimsPrinicipalFactory.cs @@ -10,8 +10,8 @@ using zero.Core.Identity; namespace zero.Core.Security { public class ZeroClaimsPrinicipalFactory : ZeroClaimsPrinicipalFactory - where TUser : class, IIdentityUserWithRoles - where TRole : class, IIdentityUserRole + where TUser : ZeroIdentityUser + where TRole : ZeroIdentityRole { public RoleManager RoleManager { get; private set; } @@ -49,7 +49,7 @@ namespace zero.Core.Security public class ZeroClaimsPrinicipalFactory : UserClaimsPrincipalFactory, IUserClaimsPrincipalFactory - where TUser : class, IIdentityUser + where TUser : ZeroIdentityUser { protected ZeroAuthOptions AuthOptions { get; private set; } diff --git a/zero.Core/Services/Localizer.cs b/zero.Core/Services/Localizer.cs index 996b7db9..33cd4263 100644 --- a/zero.Core/Services/Localizer.cs +++ b/zero.Core/Services/Localizer.cs @@ -41,7 +41,7 @@ namespace zero.Core.Services if (!Cache.TryGetValue(key, out string value)) { - ITranslation translation = LoadTranslation(key); + Translation translation = LoadTranslation(key); if (translation == null) { @@ -95,9 +95,9 @@ namespace zero.Core.Services /// /// Get translation from database or any other source /// - protected virtual ITranslation LoadTranslation(string key) + protected virtual Translation LoadTranslation(string key) { - return Session.Query().FirstOrDefault(x => x.Key == key); + return Session.Query().FirstOrDefault(x => x.Key == key); } } diff --git a/zero.Core/Utils/TableBuilder/TableExport.cs b/zero.Core/Utils/TableBuilder/TableExport.cs index 8ac7fa3c..d25d9d1d 100644 --- a/zero.Core/Utils/TableBuilder/TableExport.cs +++ b/zero.Core/Utils/TableBuilder/TableExport.cs @@ -5,7 +5,7 @@ using zero.Core.Entities; namespace zero.Core.Utils { - public abstract class TableExport : ITableExport where TEntity : IZeroEntity + public abstract class TableExport : ITableExport where TEntity : ZeroEntity { public virtual async Task Export(TableFormat format = TableFormat.Excel) { @@ -36,7 +36,7 @@ namespace zero.Core.Utils } - public interface ITableExport where TEntity : IZeroEntity + public interface ITableExport where TEntity : ZeroEntity { Task Export(TableFormat format = TableFormat.Excel); } diff --git a/zero.Core/Utils/ZeroEntityJsonConverter.cs b/zero.Core/Utils/ZeroEntityJsonConverter.cs index e18578f7..0136c958 100644 --- a/zero.Core/Utils/ZeroEntityJsonConverter.cs +++ b/zero.Core/Utils/ZeroEntityJsonConverter.cs @@ -14,7 +14,7 @@ // public ZeroEntityJsonConverter() // { // type = typeof(Ref<>); -// idProperty = nameof(Ref.Id); +// idProperty = nameof(Ref.Id); // } diff --git a/zero.Core/Validation/ApplicationValidator.cs b/zero.Core/Validation/ApplicationValidator.cs index d0aab8cb..0cb9d810 100644 --- a/zero.Core/Validation/ApplicationValidator.cs +++ b/zero.Core/Validation/ApplicationValidator.cs @@ -4,7 +4,7 @@ using zero.Core.Extensions; namespace zero.Core.Validation { - public class ApplicationValidator : ZeroValidator + public class ApplicationValidator : ZeroValidator { public ApplicationValidator() { diff --git a/zero.Core/Validation/BackofficeUserValidator.cs b/zero.Core/Validation/BackofficeUserValidator.cs index 8a99818f..796781a4 100644 --- a/zero.Core/Validation/BackofficeUserValidator.cs +++ b/zero.Core/Validation/BackofficeUserValidator.cs @@ -4,7 +4,7 @@ using zero.Core.Extensions; namespace zero.Core.Validation { - public class BackofficeUserValidator : ZeroValidator + public class BackofficeUserValidator : ZeroValidator { public BackofficeUserValidator(bool isCreate = false) { diff --git a/zero.Core/Validation/PageValidator.cs b/zero.Core/Validation/PageValidator.cs index 742b5218..b9e78424 100644 --- a/zero.Core/Validation/PageValidator.cs +++ b/zero.Core/Validation/PageValidator.cs @@ -4,7 +4,7 @@ using zero.Core.Entities; namespace zero.Core.Validation { - public class PageValidator : ZeroValidator + public class PageValidator : ZeroValidator { public PageValidator() { diff --git a/zero.Core/Validation/UserRoleValidator.cs b/zero.Core/Validation/UserRoleValidator.cs index e90eb872..e0b84f84 100644 --- a/zero.Core/Validation/UserRoleValidator.cs +++ b/zero.Core/Validation/UserRoleValidator.cs @@ -6,7 +6,7 @@ using System; namespace zero.Core.Validation { - public class UserRoleValidator : ZeroValidator + public class UserRoleValidator : ZeroValidator { const string SECTION_CLAIM = "section."; @@ -20,7 +20,7 @@ namespace zero.Core.Validation RuleFor(x => x.Claims).NotEmpty().Must((role, claims, context) => { - foreach (IUserClaim claim in claims) + foreach (UserClaim claim in claims) { if (claim.Value.StartsWith(SECTION_CLAIM, StringComparison.InvariantCultureIgnoreCase) && claim.Value.EndsWith(TRUE_CLAIM_VALUE, StringComparison.InvariantCultureIgnoreCase)) { diff --git a/zero.Core/ZeroContext.cs b/zero.Core/ZeroContext.cs index 5a12ab01..acc9e746 100644 --- a/zero.Core/ZeroContext.cs +++ b/zero.Core/ZeroContext.cs @@ -16,7 +16,7 @@ namespace zero.Core public class ZeroContext : IZeroContext { /// - public IApplication Application { get; protected set; } + public Application Application { get; protected set; } /// public string AppId { get; protected set; } @@ -31,7 +31,7 @@ namespace zero.Core public IZeroOptions Options { get; protected set; } /// - public IRoute Route { get; private set; } + public Route Route { get; private set; } /// public IResolvedRoute ResolvedRoute { get; private set; } @@ -117,7 +117,7 @@ namespace zero.Core /// /// Currently loaded application /// - IApplication Application { get; } + Application Application { get; } /// /// Current loaded application Id @@ -147,7 +147,7 @@ namespace zero.Core /// /// Matching (frontend) path route /// - IRoute Route { get; } + Route Route { get; } /// /// Matching (frontend) resolved route diff --git a/zero.Core/zero.Core.csproj b/zero.Core/zero.Core.csproj index 5970ca0d..a3553078 100644 --- a/zero.Core/zero.Core.csproj +++ b/zero.Core/zero.Core.csproj @@ -8,6 +8,12 @@ true + + + + + + @@ -27,7 +33,6 @@ - diff --git a/zero.Web.UI/app/core/editor.ts b/zero.Web.UI/app/core/editor.ts index f86e0a62..2277e4a5 100644 --- a/zero.Web.UI/app/core/editor.ts +++ b/zero.Web.UI/app/core/editor.ts @@ -146,7 +146,7 @@ class Editor /** - * Adds an info tab to the editor which outputs data for IZeroEntity. + * Adds an info tab to the editor which outputs data for ZeroEntity. * This won't work as expected for other entities as they probably do not have required properties defined. * @returns {EditorTab} */ diff --git a/zero.Web/Controllers/ApplicationsController.cs b/zero.Web/Controllers/ApplicationsController.cs index 1f978609..4f41f704 100644 --- a/zero.Web/Controllers/ApplicationsController.cs +++ b/zero.Web/Controllers/ApplicationsController.cs @@ -19,28 +19,28 @@ namespace zero.Web.Controllers } - public EditModel GetEmpty([FromServices] IApplication blueprint) => Edit(blueprint); + public EditModel GetEmpty([FromServices] Application blueprint) => Edit(blueprint); - public async Task> GetById([FromQuery] string id) => Edit(await Api.GetById(id)); + public async Task> GetById([FromQuery] string id) => Edit(await Api.GetById(id)); - public async Task> GetAll() => await Api.GetAll(); + public async Task> GetAll() => await Api.GetAll(); - public async Task> GetByQuery([FromQuery] ListBackofficeQuery query) => await Api.GetByQuery(query); + public async Task> GetByQuery([FromQuery] ListBackofficeQuery query) => await Api.GetByQuery(query); - public IReadOnlyCollection GetAllFeatures() => Options.Features.GetAllItems(); + public IReadOnlyCollection GetAllFeatures() => Options.Features.GetAllItems(); [HttpPost] [ZeroAuthorize(Permissions.Settings.Applications, PermissionsValue.Update)] - public async Task> Save([FromBody] IApplication model) => await Api.Save(model); + public async Task> Save([FromBody] Application model) => await Api.Save(model); [HttpDelete] [ZeroAuthorize(Permissions.Settings.Applications, PermissionsValue.Update)] - public async Task> Delete([FromQuery] string id) => await Api.Delete(id); + public async Task> Delete([FromQuery] string id) => await Api.Delete(id); } } diff --git a/zero.Web/Controllers/BackofficeCollectionController.cs b/zero.Web/Controllers/BackofficeCollectionController.cs index 17e93d9d..4d0ae8e3 100644 --- a/zero.Web/Controllers/BackofficeCollectionController.cs +++ b/zero.Web/Controllers/BackofficeCollectionController.cs @@ -12,7 +12,7 @@ using zero.Web.Models; namespace zero.Web.Controllers { public abstract class BackofficeCollectionController : BackofficeController - where TEntity : IZeroEntity + where TEntity : ZeroEntity where TCollection : ICollectionBase { protected TCollection Collection { get; private set; } diff --git a/zero.Web/Controllers/BackofficeController.cs b/zero.Web/Controllers/BackofficeController.cs index f238e491..b44c09b8 100644 --- a/zero.Web/Controllers/BackofficeController.cs +++ b/zero.Web/Controllers/BackofficeController.cs @@ -38,7 +38,7 @@ namespace zero.Web.Controllers /// /// Creates an edit model with appropriate options and permissions /// - public EditModel Edit(T data, bool typed = true, Action> transform = null) where T : IZeroIdEntity + public EditModel Edit(T data, bool typed = true, Action> transform = null) where T : ZeroIdEntity { Type type = typeof(T); @@ -69,7 +69,7 @@ namespace zero.Web.Controllers /// Creates an edit model with appropriate options and permissions /// public TWrapper Edit(TWrapper data, bool typed = true, Action> transform = null) - where T : IZeroIdEntity + where T : ZeroIdEntity where TWrapper : EditModel, new() { Type type = typeof(T); @@ -119,7 +119,7 @@ namespace zero.Web.Controllers } - public IList Previews(Dictionary items, Action transform = null) where T : IZeroEntity + public IList Previews(Dictionary items, Action transform = null) where T : ZeroEntity { IList previews = new List(); @@ -155,7 +155,7 @@ namespace zero.Web.Controllers - public async Task> SelectList(IAsyncEnumerable enumerable, Action transform = null) where T : IZeroEntity + public async Task> SelectList(IAsyncEnumerable enumerable, Action transform = null) where T : ZeroEntity { List items = new List(); diff --git a/zero.Web/Controllers/CountriesController.cs b/zero.Web/Controllers/CountriesController.cs index cdfe9692..4d4e6459 100644 --- a/zero.Web/Controllers/CountriesController.cs +++ b/zero.Web/Controllers/CountriesController.cs @@ -7,7 +7,7 @@ using zero.Core.Identity; namespace zero.Web.Controllers { [ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Read)] - public class CountriesController : BackofficeCollectionController + public class CountriesController : BackofficeCollectionController { public CountriesController(ICountriesCollection collection) : base(collection) { diff --git a/zero.Web/Controllers/IntegrationsController.cs b/zero.Web/Controllers/IntegrationsController.cs index fc709413..8c2d3387 100644 --- a/zero.Web/Controllers/IntegrationsController.cs +++ b/zero.Web/Controllers/IntegrationsController.cs @@ -21,25 +21,25 @@ namespace zero.Web.Controllers } - public EditModel GetEmpty([FromQuery] string alias) => Edit(Collection.GetEmpty(alias)); + public EditModel GetEmpty([FromQuery] string alias) => Edit(Collection.GetEmpty(alias)); - public async Task> GetByAlias([FromQuery] string alias) => Edit(await Collection.GetByAlias(alias)); + public async Task> GetByAlias([FromQuery] string alias) => Edit(await Collection.GetByAlias(alias)); - public async Task> GetByQuery([FromQuery] ListQuery query) => await Collection.GetByQuery(query); + public async Task> GetByQuery([FromQuery] ListQuery query) => await Collection.GetByQuery(query); public async Task> GetTypes() => await Collection.GetTypesWithStatus(); [HttpPost] - public async Task> Save([FromBody] IIntegration model) => await Collection.Save(model); + public async Task> Save([FromBody] Integration model) => await Collection.Save(model); [HttpPost] - public async Task> SaveActiveState([FromBody] Integration model) => model.IsActive ? await Collection.Activate(model.Alias) : await Collection.Deactivate(model.Alias); + public async Task> SaveActiveState([FromBody] Integration model) => model.IsActive ? await Collection.Activate(model.Alias) : await Collection.Deactivate(model.Alias); [HttpDelete] - public async Task> Delete([FromQuery] string alias) => await Collection.Delete(alias); + public async Task> Delete([FromQuery] string alias) => await Collection.Delete(alias); } } \ No newline at end of file diff --git a/zero.Web/Controllers/LanguagesController.cs b/zero.Web/Controllers/LanguagesController.cs index e3970969..3737953d 100644 --- a/zero.Web/Controllers/LanguagesController.cs +++ b/zero.Web/Controllers/LanguagesController.cs @@ -8,7 +8,7 @@ using zero.Core.Identity; namespace zero.Web.Controllers { [ZeroAuthorize(Permissions.Settings.Languages, PermissionsValue.Read)] - public class LanguagesController : BackofficeCollectionController + public class LanguagesController : BackofficeCollectionController { public LanguagesController(ILanguagesCollection collection) : base(collection) { diff --git a/zero.Web/Controllers/MailTemplatesController.cs b/zero.Web/Controllers/MailTemplatesController.cs index 7b114491..51c1c243 100644 --- a/zero.Web/Controllers/MailTemplatesController.cs +++ b/zero.Web/Controllers/MailTemplatesController.cs @@ -5,7 +5,7 @@ using zero.Core.Identity; namespace zero.Web.Controllers { [ZeroAuthorize(Permissions.Settings.Mails, PermissionsValue.Read)] - public class MailTemplatesController : BackofficeCollectionController + public class MailTemplatesController : BackofficeCollectionController { public MailTemplatesController(IMailTemplatesCollection collection) : base(collection) { diff --git a/zero.Web/Controllers/MediaController.cs b/zero.Web/Controllers/MediaController.cs index b155eb28..3d61e1d0 100644 --- a/zero.Web/Controllers/MediaController.cs +++ b/zero.Web/Controllers/MediaController.cs @@ -17,7 +17,7 @@ using zero.Web.Models; namespace zero.Web.Controllers { [ZeroAuthorize(Permissions.Sections.Media, PermissionsValue.True)] - public class MediaController : BackofficeCollectionController + public class MediaController : BackofficeCollectionController { IMediaFolderApi MediaFolderApi; IPaths Paths; @@ -38,13 +38,13 @@ namespace zero.Web.Controllers [HttpPost] - public async Task> Upload(IFormFile file, [FromForm] string folderId) => await Collection.Save(await Collection.Upload(file, folderId)); + public async Task> Upload(IFormFile file, [FromForm] string folderId) => await Collection.Save(await Collection.Upload(file, folderId)); [HttpPost] public async Task UploadTemporary(IFormFile file, [FromForm] string folderId) => await Collection.Upload(file, folderId); [HttpPost] - public async Task> Move([FromBody] ActionCopyModel model) => await Collection.Move(model.Id, model.DestinationId); + public async Task> Move([FromBody] ActionCopyModel model) => await Collection.Move(model.Id, model.DestinationId); public async Task GetAll([FromQuery] MediaListQuery query) @@ -60,8 +60,8 @@ namespace zero.Web.Controllers Type = x.Type }); - IList hierarchy = null; - IMediaFolder folder = null; + IList hierarchy = null; + MediaFolder folder = null; if (!String.IsNullOrEmpty(query.FolderId)) { diff --git a/zero.Web/Controllers/MediaFolderController.cs b/zero.Web/Controllers/MediaFolderController.cs index c451156e..3ec586d5 100644 --- a/zero.Web/Controllers/MediaFolderController.cs +++ b/zero.Web/Controllers/MediaFolderController.cs @@ -19,25 +19,25 @@ namespace zero.Web.Controllers } - public async Task> GetById([FromQuery] string id) => Edit(await Api.GetById(id)); + public async Task> GetById([FromQuery] string id) => Edit(await Api.GetById(id)); - public EditModel GetEmpty([FromServices] IMediaFolder blueprint) => Edit(blueprint); + public EditModel GetEmpty([FromServices] MediaFolder blueprint) => Edit(blueprint); - public async Task> GetHierarchy([FromQuery] string id) => await Api.GetHierarchy(id); + public async Task> GetHierarchy([FromQuery] string id) => await Api.GetHierarchy(id); public async Task> GetAllAsTree([FromQuery] string parent = null, [FromQuery] string active = null) => await Api.GetAllAsTree(parent, active); [HttpPost] - public async Task> Move([FromBody] ActionCopyModel model) => await Api.Move(model.Id, model.DestinationId); + public async Task> Move([FromBody] ActionCopyModel model) => await Api.Move(model.Id, model.DestinationId); - public async Task> Save([FromBody] IMediaFolder model) => await Api.Save(model); + public async Task> Save([FromBody] MediaFolder model) => await Api.Save(model); - public async Task> Delete([FromQuery] string id) => await Api.Delete(id); + public async Task> Delete([FromQuery] string id) => await Api.Delete(id); } } diff --git a/zero.Web/Controllers/ModulesController.cs b/zero.Web/Controllers/ModulesController.cs index 0643d4bb..29252a78 100644 --- a/zero.Web/Controllers/ModulesController.cs +++ b/zero.Web/Controllers/ModulesController.cs @@ -25,10 +25,10 @@ namespace zero.Web.Controllers public ModuleType GetModuleType([FromQuery] string alias) => Api.GetModuleType(alias); - public EditModel GetEmpty(string alias) + public EditModel GetEmpty(string alias) { ModuleType moduleType = Api.GetModuleType(alias); - IModule module = Activator.CreateInstance(moduleType.ContentType) as IModule; + Module module = Activator.CreateInstance(moduleType.ContentType) as Module; module.ModuleTypeAlias = moduleType.Alias; module.Id = IdGenerator.Create(8); diff --git a/zero.Web/Controllers/PagesController.cs b/zero.Web/Controllers/PagesController.cs index 4e40fa22..9863e259 100644 --- a/zero.Web/Controllers/PagesController.cs +++ b/zero.Web/Controllers/PagesController.cs @@ -31,25 +31,25 @@ namespace zero.Web.Controllers public PageType GetPageType([FromQuery] string alias) => Api.GetPageType(alias); - public async Task> GetById([FromQuery] string id) + public async Task> GetById([FromQuery] string id) { - IPage entity = await Api.GetById(id); + Page entity = await Api.GetById(id); if (entity == null) { return null; } - return Edit>(new PageEditModel() + return Edit>(new PageEditModel() { Entity = entity, - //Revisions = await RevisionsApi.GetPaged(id), + //Revisions = await RevisionsApi.GetPaged(id), PageType = Api.GetPageType(entity.PageTypeAlias) }); } - public async Task> GetEmpty([FromQuery] string type, [FromQuery] string parent = null) + public async Task> GetEmpty([FromQuery] string type, [FromQuery] string parent = null) { return Edit(await Api.GetEmpty(type, parent)); } @@ -61,13 +61,13 @@ namespace zero.Web.Controllers using IAsyncDocumentSession session = Store.OpenAsyncSession(); - Dictionary pages = await session.LoadAsync(ids); - Dictionary routes = await session.LoadAsync(pages.Where(x => x.Value != null).Select(x => "routes." + x.Value.Hash)); + Dictionary pages = await session.LoadAsync(ids); + Dictionary routes = await session.LoadAsync(pages.Where(x => x.Value != null).Select(x => "routes." + x.Value.Hash)); return Previews(pages, item => { PageType pageType = pageTypes.FirstOrDefault(x => x.Alias == item.PageTypeAlias); - IRoute route = null; + Route route = null; if (!routes.TryGetValue("routes." + item.Hash, out route) || route == null) { @@ -88,22 +88,22 @@ namespace zero.Web.Controllers } - public async Task> GetRevisions([FromQuery] string id, [FromQuery] int page = 1) => await RevisionsApi.GetPaged(id, page); + public async Task> GetRevisions([FromQuery] string id, [FromQuery] int page = 1) => await RevisionsApi.GetPaged(id, page); - public async Task> Save([FromBody] IPage model) => await Api.Save(model); + public async Task> Save([FromBody] Page model) => await Api.Save(model); [HttpPost] - public async Task>> SaveSorting([FromBody] string[] ids) => await Api.SaveSorting(ids); + public async Task>> SaveSorting([FromBody] string[] ids) => await Api.SaveSorting(ids); [HttpPost] - public async Task> Move([FromBody] ActionCopyModel model) => await Api.Move(model.Id, model.DestinationId); + public async Task> Move([FromBody] ActionCopyModel model) => await Api.Move(model.Id, model.DestinationId); [HttpPost] - public async Task> Copy([FromBody] ActionCopyModel model) => await Api.Copy(model.Id, model.DestinationId, model.IncludeDescendants); + public async Task> Copy([FromBody] ActionCopyModel model) => await Api.Copy(model.Id, model.DestinationId, model.IncludeDescendants); [HttpPost] diff --git a/zero.Web/Controllers/PreviewController.cs b/zero.Web/Controllers/PreviewController.cs index fd098bee..e1f25d1b 100644 --- a/zero.Web/Controllers/PreviewController.cs +++ b/zero.Web/Controllers/PreviewController.cs @@ -16,19 +16,19 @@ namespace zero.Web.Controllers } - public async Task> GetById([FromQuery] string id) => Edit(await Api.GetById(id)); + public async Task> GetById([FromQuery] string id) => Edit(await Api.GetById(id)); - public async Task> Add([FromBody] IZeroEntity model) + public async Task> Add([FromBody] ZeroEntity model) { - EntityResult preview = await Api.Add(model); + EntityResult preview = await Api.Add(model); return EntityResult.From(preview, preview.Model?.Id); } - public async Task> Update([FromQuery] string id, [FromBody] IZeroEntity model) + public async Task> Update([FromQuery] string id, [FromBody] ZeroEntity model) { - EntityResult preview = await Api.Update(id, model); + EntityResult preview = await Api.Update(id, model); return EntityResult.From(preview, id); } } diff --git a/zero.Web/Controllers/RecycleBinController.cs b/zero.Web/Controllers/RecycleBinController.cs index d86282d7..3c44e316 100644 --- a/zero.Web/Controllers/RecycleBinController.cs +++ b/zero.Web/Controllers/RecycleBinController.cs @@ -15,7 +15,7 @@ namespace zero.Web.Controllers } - public async Task> GetByQuery([FromQuery] RecycleBinListQuery query) + public async Task> GetByQuery([FromQuery] RecycleBinListQuery query) { query.IncludeInactive = true; return await Api.GetByQuery(query); @@ -26,11 +26,11 @@ namespace zero.Web.Controllers [HttpDelete] - public async Task> Delete([FromQuery] string id) => await Api.Delete(id); + public async Task> Delete([FromQuery] string id) => await Api.Delete(id); [HttpDelete] - public async Task> DeleteByGroup([FromQuery] string group) => await Api.DeleteByGroup(group); + public async Task> DeleteByGroup([FromQuery] string group) => await Api.DeleteByGroup(group); } } diff --git a/zero.Web/Controllers/SettingsController.cs b/zero.Web/Controllers/SettingsController.cs index 670e8e94..54b57cfe 100644 --- a/zero.Web/Controllers/SettingsController.cs +++ b/zero.Web/Controllers/SettingsController.cs @@ -67,7 +67,7 @@ namespace zero.Web.Controllers } } - IList applications = new List(); + IList applications = new List(); if (Permission.CanReadKey(permissions, Permissions.Settings.Applications, false)) { diff --git a/zero.Web/Controllers/SpacesController.cs b/zero.Web/Controllers/SpacesController.cs index e9382b31..b12ef485 100644 --- a/zero.Web/Controllers/SpacesController.cs +++ b/zero.Web/Controllers/SpacesController.cs @@ -35,7 +35,7 @@ namespace zero.Web.Controllers public List GetAll() => Api.GetAll().Where(space => CanReadSpace(space.Alias)).ToList(); - public async Task GetList([FromQuery] string alias, [FromQuery] ListBackofficeQuery query = null) + public async Task GetList([FromQuery] string alias, [FromQuery] ListBackofficeQuery query = null) { if (!CanReadSpace(alias)) { @@ -54,7 +54,7 @@ namespace zero.Web.Controllers } Space space = Api.GetByAlias(alias); - ISpaceContent model = null; + SpaceContent model = null; if (space == null) { @@ -79,7 +79,7 @@ namespace zero.Web.Controllers /// /// Save content item /// - public async Task Save([FromBody] ISpaceContent model) + public async Task Save([FromBody] SpaceContent model) { if (!CanWriteSpace(model.SpaceAlias)) { diff --git a/zero.Web/Controllers/TranslationsController.cs b/zero.Web/Controllers/TranslationsController.cs index 1a2e0b85..ac760c4a 100644 --- a/zero.Web/Controllers/TranslationsController.cs +++ b/zero.Web/Controllers/TranslationsController.cs @@ -10,13 +10,13 @@ using zero.Core.Identity; namespace zero.Web.Controllers { [ZeroAuthorize(Permissions.Settings.Translations, PermissionsValue.Read)] - public class TranslationsController : BackofficeCollectionController + public class TranslationsController : BackofficeCollectionController { public TranslationsController(ITranslationsCollection collection) : base(collection) { } - public override async Task> GetByQuery([FromQuery] ListBackofficeQuery query) + public override async Task> GetByQuery([FromQuery] ListBackofficeQuery query) { query.SearchFor(entity => entity.Key, entity => entity.Value); return await Collection.Query.OrderByDescending(x => x.CreatedDate).ToQueriedListAsync(query); diff --git a/zero.Web/Controllers/UserRolesController.cs b/zero.Web/Controllers/UserRolesController.cs index 50755c7c..48654796 100644 --- a/zero.Web/Controllers/UserRolesController.cs +++ b/zero.Web/Controllers/UserRolesController.cs @@ -22,20 +22,20 @@ namespace zero.Web.Controllers } - public async Task> GetById([FromQuery] string id) => Edit(await Api.GetById(id)); + public async Task> GetById([FromQuery] string id) => Edit(await Api.GetById(id)); - public async Task> GetAll() => await Api.GetAll(); + public async Task> GetAll() => await Api.GetAll(); public IList GetAllPermissions() => PermissionsApi.GetAll(); [ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)] - public async Task> Save([FromBody] IBackofficeUserRole model) => await Api.Save(model); + public async Task> Save([FromBody] BackofficeUserRole model) => await Api.Save(model); [ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)] - public async Task> Delete([FromQuery] string id) => await Api.Delete(id); + public async Task> Delete([FromQuery] string id) => await Api.Delete(id); } } diff --git a/zero.Web/Controllers/UsersController.cs b/zero.Web/Controllers/UsersController.cs index 6c5ae225..0a29435d 100644 --- a/zero.Web/Controllers/UsersController.cs +++ b/zero.Web/Controllers/UsersController.cs @@ -25,10 +25,10 @@ namespace zero.Web.Controllers } - public async Task> GetById([FromQuery] string id) => Edit(await Api.GetUserById(id)); + public async Task> GetById([FromQuery] string id) => Edit(await Api.GetUserById(id)); - public async Task> GetAll([FromQuery] ListBackofficeQuery query) => await Api.GetByQuery(query); + public async Task> GetAll([FromQuery] ListBackofficeQuery query) => await Api.GetByQuery(query); public IList GetAllPermissions() => PermissionsApi.GetAll(); @@ -54,18 +54,18 @@ namespace zero.Web.Controllers [ZeroAuthorize] - public async Task> UpdatePassword([FromBody] UserPasswordEditModel model) + public async Task> UpdatePassword([FromBody] UserPasswordEditModel model) { - EntityResult result; + EntityResult result; if (model.NewPassword != model.ConfirmNewPassword) { - result = EntityResult.Fail(nameof(model.NewPassword), "@errors.changepassword.newpasswordsnotmatching"); + result = EntityResult.Fail(nameof(model.NewPassword), "@errors.changepassword.newpasswordsnotmatching"); } else { BackofficeUser user = await AuthenticationApi.GetUser(); - result = await Api.UpdatePassword(user as IBackofficeUser, model.CurrentPassword, model.NewPassword); + result = await Api.UpdatePassword(user as BackofficeUser, model.CurrentPassword, model.NewPassword); if (result.IsSuccess) { @@ -78,31 +78,31 @@ namespace zero.Web.Controllers [ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)] - public async Task> Disable([FromBody] IBackofficeUser model) + public async Task> Disable([FromBody] BackofficeUser model) { - IBackofficeUser entity = await Api.GetUserById(model.Id); + BackofficeUser entity = await Api.GetUserById(model.Id); return await Api.Disable(entity); } [ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)] - public async Task> Enable([FromBody] IBackofficeUser model) + public async Task> Enable([FromBody] BackofficeUser model) { - IBackofficeUser entity = await Api.GetUserById(model.Id); + BackofficeUser entity = await Api.GetUserById(model.Id); return await Api.Enable(entity); } [ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)] - public async Task> Save([FromBody] IBackofficeUser model) => await Api.Save(model); + public async Task> Save([FromBody] BackofficeUser model) => await Api.Save(model); [ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)] // TODO do not need settings.users authorization for editing current user profiles - public async Task> SaveCurrent([FromBody] IBackofficeUser model) => await Api.Save(model); + public async Task> SaveCurrent([FromBody] BackofficeUser model) => await Api.Save(model); [ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Update)] - public async Task> Delete([FromQuery] string id) => await Api.Delete(id); + public async Task> Delete([FromQuery] string id) => await Api.Delete(id); } } diff --git a/zero.Web/Controllers/ZeroController.cs b/zero.Web/Controllers/ZeroController.cs index 5581571e..2c1cb6d7 100644 --- a/zero.Web/Controllers/ZeroController.cs +++ b/zero.Web/Controllers/ZeroController.cs @@ -17,7 +17,7 @@ namespace zero.Web.Controllers public abstract class ZeroController : Controller where T : IResolvedRoute { - protected IApplication Application { get; set; } + protected Application Application { get; set; } protected virtual T Route { get; set; } diff --git a/zero.Web/Defaults/ZeroBackofficePlugin.cs b/zero.Web/Defaults/ZeroBackofficePlugin.cs index 0b37255b..f3a07945 100644 --- a/zero.Web/Defaults/ZeroBackofficePlugin.cs +++ b/zero.Web/Defaults/ZeroBackofficePlugin.cs @@ -58,27 +58,27 @@ namespace zero.Web.Defaults services.AddScoped(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); - services.AddTransient, ApplicationValidator>(); - services.AddTransient, CountryValidator>(); - services.AddTransient, MailTemplateValidator>(); - services.AddTransient, LanguageValidator>(); - services.AddTransient, TranslationValidator>(); - services.AddTransient, PageValidator>(); - services.AddTransient, MediaValidator>(); - services.AddTransient, MediaFolderValidator>(); - services.AddTransient, UserRoleValidator>(); - services.AddTransient, BackofficeUserValidator>(); + services.AddTransient, ApplicationValidator>(); + services.AddTransient, CountryValidator>(); + services.AddTransient, MailTemplateValidator>(); + services.AddTransient, LanguageValidator>(); + services.AddTransient, TranslationValidator>(); + services.AddTransient, PageValidator>(); + services.AddTransient, MediaValidator>(); + services.AddTransient, MediaFolderValidator>(); + services.AddTransient, UserRoleValidator>(); + services.AddTransient, BackofficeUserValidator>(); services.AddTransient(); services.AddTransient(); diff --git a/zero.Web/Filters/ZeroBackofficeAttribute.cs b/zero.Web/Filters/ZeroBackofficeAttribute.cs index 0264daab..2aed6f38 100644 --- a/zero.Web/Filters/ZeroBackofficeAttribute.cs +++ b/zero.Web/Filters/ZeroBackofficeAttribute.cs @@ -36,7 +36,7 @@ // if (result != null) // { -// IZeroEntity model = result.Value as IZeroEntity; +// ZeroEntity model = result.Value as ZeroEntity; // if (model != null) // { diff --git a/zero.Web/Models/MediaListResultModel.cs b/zero.Web/Models/MediaListResultModel.cs index 51ee14ba..2aebe262 100644 --- a/zero.Web/Models/MediaListResultModel.cs +++ b/zero.Web/Models/MediaListResultModel.cs @@ -7,16 +7,16 @@ namespace zero.Web.Models { public IEnumerable Folders { get; private set; } - public IEnumerable FolderHierarchy { get; private set; } + public IEnumerable FolderHierarchy { get; private set; } - public IMediaFolder Folder { get; private set; } + public MediaFolder Folder { get; private set; } public MediaListResultModel(ListResult items, IEnumerable folders) : base(items.Items, items.TotalItems, items.Page, items.PageSize) { Folders = folders; } - public MediaListResultModel(ListResult items, IEnumerable folders, IMediaFolder currentFolder, IEnumerable hierarchy) : this(items, folders) + public MediaListResultModel(ListResult items, IEnumerable folders, MediaFolder currentFolder, IEnumerable hierarchy) : this(items, folders) { Folder = currentFolder; FolderHierarchy = hierarchy; diff --git a/zero.Web/Models/PageEditModel.cs b/zero.Web/Models/PageEditModel.cs index 3557a542..2ce57be3 100644 --- a/zero.Web/Models/PageEditModel.cs +++ b/zero.Web/Models/PageEditModel.cs @@ -7,7 +7,7 @@ using zero.Core.Entities; namespace zero.Web.Models { - public class PageEditModel : EditModel where T : IPage + public class PageEditModel : EditModel where T : Page { public PageType PageType { get; set; } diff --git a/zero.Web/Models/UserEditModel.cs b/zero.Web/Models/UserEditModel.cs index 3425009b..40355974 100644 --- a/zero.Web/Models/UserEditModel.cs +++ b/zero.Web/Models/UserEditModel.cs @@ -20,7 +20,7 @@ namespace zero.Web.Models public List Roles { get; set; } = new List(); - public List Claims { get; set; } = new List(); + public List Claims { get; set; } = new List(); public DateTimeOffset? LockoutEnd { get; set; } diff --git a/zero.Web/Models/UserRoleEditModel.cs b/zero.Web/Models/UserRoleEditModel.cs index 9f927e7e..1af40662 100644 --- a/zero.Web/Models/UserRoleEditModel.cs +++ b/zero.Web/Models/UserRoleEditModel.cs @@ -12,7 +12,7 @@ namespace zero.Web.Models public string Icon { get; set; } - // TODO use IUserClaim and resolve to default type + // TODO use UserClaim and resolve to default type // see here: http://www.dotnet-programming.com/post/2017/05/08/Aspnet-core-Deserializing-Json-with-Dependency-Injection.aspx public List Claims { get; set; } } diff --git a/zero.Web/Sections/DashboardSection.cs b/zero.Web/Sections/DashboardSection.cs index 28722794..a3406762 100644 --- a/zero.Web/Sections/DashboardSection.cs +++ b/zero.Web/Sections/DashboardSection.cs @@ -7,7 +7,7 @@ namespace zero.Web.Sections /// /// The dashboard aggregates data from all sections /// - public class DashboardSection : ISection, IZeroInternal + public class DashboardSection : IInternalSection { /// public string Alias => Constants.Sections.Dashboard; diff --git a/zero.Web/Sections/MediaSection.cs b/zero.Web/Sections/MediaSection.cs index e1cb362c..9a5595d2 100644 --- a/zero.Web/Sections/MediaSection.cs +++ b/zero.Web/Sections/MediaSection.cs @@ -7,7 +7,7 @@ namespace zero.Web.Sections /// /// Media items (images, videos, documents) grouped in folders /// - public class MediaSection : ISection, IZeroInternal + public class MediaSection : IInternalSection { /// public string Alias => Constants.Sections.Media; diff --git a/zero.Web/Sections/PagesSection.cs b/zero.Web/Sections/PagesSection.cs index a602afd5..bd7d7be5 100644 --- a/zero.Web/Sections/PagesSection.cs +++ b/zero.Web/Sections/PagesSection.cs @@ -7,7 +7,7 @@ namespace zero.Web.Sections /// /// Manage the page tree in this section /// - public class PagesSection : ISection, IZeroInternal + public class PagesSection : IInternalSection { /// public string Alias => Constants.Sections.Pages; diff --git a/zero.Web/Sections/SettingsSection.cs b/zero.Web/Sections/SettingsSection.cs index 07d4239d..2d5204ee 100644 --- a/zero.Web/Sections/SettingsSection.cs +++ b/zero.Web/Sections/SettingsSection.cs @@ -7,7 +7,7 @@ namespace zero.Web.Sections /// /// Website and backoffice settings /// - public class SettingsSection : ISection, IZeroInternal + public class SettingsSection : IInternalSection { /// public string Alias => Constants.Sections.Settings; diff --git a/zero.Web/Sections/SpacesSection.cs b/zero.Web/Sections/SpacesSection.cs index ce62da6e..9ef08ea8 100644 --- a/zero.Web/Sections/SpacesSection.cs +++ b/zero.Web/Sections/SpacesSection.cs @@ -7,7 +7,7 @@ namespace zero.Web.Sections /// /// Global list entities /// - public class SpacesSection : ISection, IZeroInternal + public class SpacesSection : IInternalSection { /// public string Alias => Constants.Sections.Spaces; diff --git a/zero.Web/Security/AuthenticationBuilderExtensions.cs b/zero.Web/Security/AuthenticationBuilderExtensions.cs index d89d8f25..3de89cd9 100644 --- a/zero.Web/Security/AuthenticationBuilderExtensions.cs +++ b/zero.Web/Security/AuthenticationBuilderExtensions.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using zero.Core; using zero.Core.Entities; using zero.Core.Extensions; -using zero.Core.Identity; using zero.Core.Options; using zero.Core.Security; @@ -17,14 +16,14 @@ namespace zero.Web.Security public static class AuthenticationBuilderExtensions { public static AuthenticationBuilder AddZeroBackofficeCookie(this AuthenticationBuilder builder, Action> setupAction = null) - where TUser : class, IBackofficeUser - where TRole : class, IBackofficeUserRole + where TUser : BackofficeUser + where TRole : BackofficeUserRole { return builder.AddCookie(Constants.Auth.BackofficeScheme, Constants.Auth.BackofficeDisplayName, true, b => { b.Configure((options, zero) => { - options.ExpireTimeSpan = TimeSpan.FromMinutes(30); + options.ExpireTimeSpan = TimeSpan.FromMinutes(90); options.Cookie.Name = Constants.Auth.BackofficeCookieName; options.CookieManager = new ContextualCookieManager((ctx, key) => @@ -49,8 +48,8 @@ namespace zero.Web.Security public static AuthenticationBuilder AddZeroCookie(this AuthenticationBuilder builder, string scheme, string cookieDisplayName = null, Action> setupAction = null) - where TUser : class, IIdentityUserWithRoles - where TRole : class, IIdentityUserRole + where TUser : ZeroIdentityUser + where TRole : ZeroIdentityRole { return builder.AddCookie(scheme, cookieDisplayName, false, setupAction); } @@ -58,7 +57,7 @@ namespace zero.Web.Security public static AuthenticationBuilder AddZeroCookie(this AuthenticationBuilder builder, string scheme, string cookieDisplayName = null, Action> setupAction = null) - where TUser : class, IIdentityUser + where TUser : ZeroIdentityUser { return builder.AddCookie(scheme, cookieDisplayName, false, setupAction); } @@ -66,7 +65,7 @@ namespace zero.Web.Security static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string scheme, string displayName, bool isBackoffice, Action> setupAction = null) - where TUser : class, IIdentityUser + where TUser : ZeroIdentityUser { IServiceCollection services = builder.Services; diff --git a/zero.Web/ViewHelpers/ZeroMediaHelper.cs b/zero.Web/ViewHelpers/ZeroMediaHelper.cs index 20aa4533..a61c8853 100644 --- a/zero.Web/ViewHelpers/ZeroMediaHelper.cs +++ b/zero.Web/ViewHelpers/ZeroMediaHelper.cs @@ -18,7 +18,7 @@ namespace zero.Web.ViewHelpers /// /// Media cache for repetitive queries within an HTTP request /// - Dictionary Cache { get; set; } = new Dictionary(); + Dictionary Cache { get; set; } = new Dictionary(); public ZeroMediaHelper(IHttpContextAccessor httpContextAccessor, IMediaApi mediaApi) @@ -29,14 +29,14 @@ namespace zero.Web.ViewHelpers /// - public async Task GetById(string id) + public async Task GetById(string id) { if (id.IsNullOrEmpty()) { return null; } - if (!Cache.TryGetValue(id, out IMedia media)) + if (!Cache.TryGetValue(id, out Media media)) { media = await MediaApi.GetById(id); Cache.Add(id, media); @@ -47,14 +47,14 @@ namespace zero.Web.ViewHelpers /// - public async Task> GetByIds(string[] ids) + public async Task> GetByIds(string[] ids) { HashSet remoteIds = new HashSet(); - Dictionary items = new Dictionary(); + Dictionary items = new Dictionary(); foreach (string id in ids) { - if (Cache.TryGetValue(id, out IMedia media)) + if (Cache.TryGetValue(id, out Media media)) { items.Add(id, media); } @@ -66,7 +66,7 @@ namespace zero.Web.ViewHelpers if (remoteIds.Count > 0) { - Dictionary remoteItems = await MediaApi.GetById(remoteIds); + Dictionary remoteItems = await MediaApi.GetById(remoteIds); foreach (var item in remoteItems) { @@ -82,7 +82,7 @@ namespace zero.Web.ViewHelpers /// public async Task GetUrl(string id, bool isAbsolute = false) { - IMedia media = await GetById(id); + Media media = await GetById(id); return media?.Source.TrimStart("url://"); } @@ -90,7 +90,7 @@ namespace zero.Web.ViewHelpers /// public async Task> GetUrls(string[] ids, bool isAbsolute = false) { - Dictionary medias = await GetByIds(ids); + Dictionary medias = await GetByIds(ids); return medias.ToDictionary(x => x.Key, x => x.Value?.Source.TrimStart("url://")); } } @@ -101,12 +101,12 @@ namespace zero.Web.ViewHelpers /// /// Get media by Id /// - Task GetById(string id); + Task GetById(string id); /// /// Get media items by Ids /// - Task> GetByIds(string[] ids); + Task> GetByIds(string[] ids); /// /// Get source for a media item diff --git a/zero.Web/ViewHelpers/ZeroPageHelper.cs b/zero.Web/ViewHelpers/ZeroPageHelper.cs index 4be1fe83..45fe4f5f 100644 --- a/zero.Web/ViewHelpers/ZeroPageHelper.cs +++ b/zero.Web/ViewHelpers/ZeroPageHelper.cs @@ -18,7 +18,7 @@ namespace zero.Web.ViewHelpers /// /// Media cache for repetitive queries within an HTTP request /// - Dictionary Cache { get; set; } = new Dictionary(); + Dictionary Cache { get; set; } = new Dictionary(); public ZeroPageHelper(IHttpContextAccessor httpContextAccessor, IMediaApi mediaApi) @@ -29,14 +29,14 @@ namespace zero.Web.ViewHelpers /// - public async Task GetById(string id) + public async Task GetById(string id) { if (id.IsNullOrEmpty()) { return null; } - if (!Cache.TryGetValue(id, out IMedia media)) + if (!Cache.TryGetValue(id, out Media media)) { media = await MediaApi.GetById(id); Cache.Add(id, media); @@ -47,14 +47,14 @@ namespace zero.Web.ViewHelpers /// - public async Task> GetByIds(string[] ids) + public async Task> GetByIds(string[] ids) { HashSet remoteIds = new HashSet(); - Dictionary items = new Dictionary(); + Dictionary items = new Dictionary(); foreach (string id in ids) { - if (Cache.TryGetValue(id, out IMedia media)) + if (Cache.TryGetValue(id, out Media media)) { items.Add(id, media); } @@ -66,7 +66,7 @@ namespace zero.Web.ViewHelpers if (remoteIds.Count > 0) { - Dictionary remoteItems = await MediaApi.GetById(remoteIds); + Dictionary remoteItems = await MediaApi.GetById(remoteIds); foreach (var item in remoteItems) { @@ -82,7 +82,7 @@ namespace zero.Web.ViewHelpers /// public async Task GetUrl(string id, bool isAbsolute = false) { - IMedia media = await GetById(id); + Media media = await GetById(id); return media?.Source; } @@ -90,7 +90,7 @@ namespace zero.Web.ViewHelpers /// public async Task> GetUrls(string[] ids, bool isAbsolute = false) { - Dictionary medias = await GetByIds(ids); + Dictionary medias = await GetByIds(ids); return medias.ToDictionary(x => x.Key, x => x.Value?.Source); } } @@ -101,12 +101,12 @@ namespace zero.Web.ViewHelpers /// /// Get media by Id /// - Task GetById(string id); + Task GetById(string id); /// /// Get media items by Ids /// - Task> GetByIds(string[] ids); + Task> GetByIds(string[] ids); /// /// Get source for a media item diff --git a/zero.Web/Views/index.tpl.html b/zero.Web/Views/index.tpl.html new file mode 100644 index 00000000..8698a332 --- /dev/null +++ b/zero.Web/Views/index.tpl.html @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + {{styles}} + zero + + +
+ {{svg}} + + + {{scripts}} + + \ No newline at end of file diff --git a/zero.Web/ZeroVue.cs b/zero.Web/ZeroVue.cs index 9e8fe9f2..fd9be8d9 100644 --- a/zero.Web/ZeroVue.cs +++ b/zero.Web/ZeroVue.cs @@ -136,7 +136,7 @@ namespace zero.Web continue; } - bool isExternal = !(section is IZeroInternal); + bool isExternal = !(section is IInternalSection); string url = Safenames.Alias(section.Alias).EnsureStartsWith('/'); if (section.Alias == Constants.Sections.Dashboard) @@ -236,7 +236,7 @@ namespace zero.Web continue; } - bool isPlugin = !(area is IZeroInternal); + bool isPlugin = !(area is InternalSettingsArea); ZeroVueSettingsArea vueArea = new ZeroVueSettingsArea() { @@ -270,7 +270,7 @@ namespace zero.Web ///
async Task> CreateApplications() { - IList applications = await ApplicationsApi.GetAll(); + IList applications = await ApplicationsApi.GetAll(); return applications.OrderBy(app => app.Sort).Select(app => new ZeroVueApplication() { @@ -329,11 +329,11 @@ namespace zero.Web IList CreateIconSets() { List result = new(); - IReadOnlyCollection sets = Options.Icons.GetAllItems(); + IReadOnlyCollection sets = Options.Icons.GetAllItems(); StringBuilder svg = new(); - foreach (IIconSet set in sets) + foreach (IconSet set in sets) { string path = Paths.Map(set.SpritePath.TrimStart('/'));