Implements directory browser dialog, part 1: file system treeview

This commit is contained in:
BinaryAlley committed 2024-09-15 13:07:53 +03:00
1 parent 4a53348013
commit 4e4ecbbfca
318 files changed
+6012 -1184

No files matched your search

@@ -1,11 +1,15 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.Models.Books;
using Lumina.Application.Common.Models.Common;
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.Common.Errors;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.DataAccess.Core.Repositories.Books;
@@ -36,25 +40,25 @@ internal sealed class BookRepository : IBookRepository
/// </summary>
/// <param name="book">The book to add.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
public async Task<ErrorOr<Created>> InsertAsync(BookDto book, CancellationToken cancellationToken)
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
public async Task<ErrorOr<Created>> InsertAsync(BookModel book, CancellationToken cancellationToken)
{
var jobExists = await _luminaDbContext.Books.AnyAsync(_book => _book.Id == book.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
if (jobExists)
return Errors.WrittenContent.BookAlreadyExists;
// fetch existing tags and genres
var existingTags = await _luminaDbContext.Set<TagDto>()
var existingTags = await _luminaDbContext.Set<TagModel>()
.Where(t => book.Tags.Select(bt => bt.Name).Contains(t.Name))
.ToListAsync(cancellationToken);
.ToListAsync(cancellationToken).ConfigureAwait(false);
var existingGenres = await _luminaDbContext.Set<GenreDto>()
var existingGenres = await _luminaDbContext.Set<GenreModel>()
.Where(g => book.Genres.Select(bg => bg.Name).Contains(g.Name))
.ToListAsync(cancellationToken);
.ToListAsync(cancellationToken).ConfigureAwait(false);
// replace tags and genres in the book with existing ones
book.Tags = new HashSet<TagDto>(book.Tags.Select(tag => existingTags.FirstOrDefault(existingTag => existingTag.Name == tag.Name) ?? tag));
book.Genres = new HashSet<GenreDto>(book.Genres.Select(genre => existingGenres.FirstOrDefault(existingGenre => existingGenre.Name == genre.Name) ?? genre));
book.Tags = new HashSet<TagModel>(book.Tags.Select(tag => existingTags.FirstOrDefault(existingTag => existingTag.Name == tag.Name) ?? tag));
book.Genres = new HashSet<GenreModel>(book.Genres.Select(genre => existingGenres.FirstOrDefault(existingGenre => existingGenre.Name == genre.Name) ?? genre));
_luminaDbContext.Books.Add(book);
return Result.Created;
@@ -64,8 +68,8 @@ internal sealed class BookRepository : IBookRepository
/// Gets all books.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{T}"/> containing either a collection of <see cref="BookDto"/>, or an error.</returns>
public async Task<ErrorOr<IEnumerable<BookDto>>> GetAllAsync(CancellationToken cancellationToken)
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="BookModel"/>, or an error.</returns>
public async Task<ErrorOr<IEnumerable<BookModel>>> GetAllAsync(CancellationToken cancellationToken)
{
return await _luminaDbContext.Books
.Include(book => book.Tags)
@@ -1,7 +1,7 @@
namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
/// <summary>
/// Repositories abstract factory.
/// Interface for the repositories factory.
/// </summary>
public interface IRepositoryFactory
{
@@ -1,5 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
@@ -14,6 +17,9 @@ public class RepositoryDictionary
#endregion
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the number of added repositories.
/// </summary>
public int Count { get { return _container.Count; } }
#endregion
@@ -1,11 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Microsoft.Extensions.DependencyInjection;
using System;
#endregion
namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
/// <summary>
/// Concrete implementation for the repositories abstract factory.
/// Concrete implementation for the repositories factory.
/// </summary>
public class RepositoryFactory : IRepositoryFactory
{
@@ -15,7 +16,7 @@ public class RepositoryFactory : IRepositoryFactory
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Overload C-tor.
/// Initializes a new instance of the <see cref="RepositoryFactory"/> class.
/// </summary>
/// <param name="serviceProvider">The service provider.</param>
public RepositoryFactory(IServiceProvider serviceProvider)