mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 01:11:10 +00:00
Implements directory browser dialog, part 1: file system treeview
This commit is contained in:
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)
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
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.Domain.Common.Events;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Core.UoW;
|
||||
@@ -15,12 +18,12 @@ namespace Lumina.DataAccess.Core.UoW;
|
||||
public class LuminaDbContext : DbContext
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
public virtual DbSet<BookDto> Books { get; set; } = null!;
|
||||
public virtual DbSet<BookModel> Books { get; set; } = null!;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// Initializes a new instance of the <see cref="LuminaDbContext"/> class.
|
||||
/// </summary>
|
||||
/// <param name="options">The options for configuring the database context.</param>
|
||||
public LuminaDbContext(DbContextOptions<LuminaDbContext> options) : base(options)
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.DataAccess.Core.Repositories.Common.Factory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Core.UoW;
|
||||
@@ -18,14 +23,17 @@ public class UnitOfWork : IUnitOfWork
|
||||
#endregion
|
||||
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets or sets the collection of available repositories.
|
||||
/// </summary>
|
||||
internal RepositoryDictionary Repositories { get; private set; } = new RepositoryDictionary();
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// Initializes a new instance of the <see cref="UnitOfWork"/> class.
|
||||
/// </summary>
|
||||
/// <param name="repositoryFactory">The abstract factory used to generate repositories.</param>
|
||||
/// <param name="repositoryFactory">The factory used to generate repositories.</param>
|
||||
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
|
||||
public UnitOfWork(IRepositoryFactory repositoryFactory, LuminaDbContext luminaDbContext)
|
||||
{
|
||||
@@ -95,7 +103,7 @@ public class UnitOfWork : IUnitOfWork
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public async Task SaveChangesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await _luminaDbContext.SaveChangesAsync(cancellationToken);
|
||||
await _luminaDbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user