chore: Refactor project structure and update DI setup

Die Datei `DIExtensions.cs` wurde erheblich überarbeitet, um Abhängigkeiten von der Schicht `DigitalData.UserManager.Infrastructure` zu entfernen. Die Methode `AddUserManager` wurde vereinfacht und eine Methode `AddEncryptor` hinzugefügt. Die Projektverweise auf die Infrastrukturebene in der Anwendungsprojektdatei wurden entfernt. Aktualisierte Servicedateien zur Verwendung neuer Repository-Schnittstellen aus „DigitalData.UserManager.Application.Contracts.Repositories“. Repository-Schnittstellen wurden in den Namensraum für Anwendungsverträge verschoben und ihre Definitionen aktualisiert. Einführung von `DependencyInjection.cs` für die Handhabung von Infrastrukturdienstregistrierungen. Aktualisierte Repository-Implementierungen, um sie an die neue Struktur anzupassen, die Trennung von Belangen zu verbessern und die Injektion von Abhängigkeiten zu vereinfachen.
This commit is contained in:
Developer 02 2025-04-16 11:02:44 +02:00
parent 239a5708a7
commit 2d792c8544
32 changed files with 226 additions and 201 deletions

View File

@ -0,0 +1,9 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Application.Contracts.Repositories;
public interface IClientUserRepository : ICRUDRepository<ClientUser, int>
{
Task<IEnumerable<ClientUser>> ReadAsync(bool readOnly = true, int? userId = null);
}

View File

@ -0,0 +1,27 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Application.Contracts.Repositories;
public interface IGroupOfUserRepository : ICRUDRepository<GroupOfUser, int>
{
IQueryable<GroupOfUser> ReadByGroupId(int groupId);
Task<IEnumerable<GroupOfUser>> ReadByGroupUserIdAsync(int groupId, int userId);
Task<IEnumerable<GroupOfUser>> ReadAllAsyncWithGroup();
Task<IEnumerable<GroupOfUser>> ReadAllAsyncWithUser();
Task<IEnumerable<GroupOfUser>> ReadAllAsyncWithGroupAndUser();
Task<IEnumerable<GroupOfUser>> ReadByUsernameAsync(string username);
Task<IEnumerable<GroupOfUser>> ReadByUserIdAsync(int userId);
// merge all GroupOfUserRepository-methods conditionally under this method
Task<IEnumerable<GroupOfUser>> ReadAsync(
bool readOnly = true,
bool withGroup = true, bool withUser = true,
int? id = null, int? groupId = null, int? userId = null, string? username = null);
}

View File

@ -0,0 +1,8 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Application.Contracts.Repositories;
public interface IGroupRepository : ICRUDRepository<Group, int>
{
}

View File

@ -0,0 +1,13 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Application.Contracts.Repositories;
public interface IModuleOfUserRepository : ICRUDRepository<ModuleOfUser, int>
{
IQueryable<ModuleOfUser> ReadByModuleId(int moduleId);
Task<IEnumerable<ModuleOfUser>> ReadByModelUserIdAsync(int moduleId, int userId);
Task<IEnumerable<ModuleOfUser>> ReadByUserAsync(string username);
}

View File

@ -0,0 +1,8 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Application.Contracts.Repositories;
public interface IModuleRepository : ICRUDRepository<Module, int>
{
}

View File

@ -0,0 +1,11 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Application.Contracts.Repositories;
public interface IUserRepRepository : ICRUDRepository<UserRep, int>
{
Task<IEnumerable<UserRep>> ReadAllAsync(
bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false,
int? userId = null, int? repUserId = null, int? groupId = null, int? repGroupId = null, bool readOnly = true);
}

View File

@ -0,0 +1,17 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Application.Contracts.Repositories;
public interface IUserRepository : ICRUDRepository<User, int>
{
Task<IEnumerable<User>> ReadByModuleIdAsync(int moduleId);
Task<IEnumerable<User>> ReadUnassignedByModuleIdAsync(int moduleId);
Task<IEnumerable<User>> ReadByGroupIdAsync(int groupId);
Task<IEnumerable<User>> ReadUnassignedByGroupIdAsync(int groupId);
Task<User?> ReadByUsernameAsync(string username);
}

View File

@ -2,9 +2,6 @@
using DigitalData.UserManager.Application.MappingProfiles;
using DigitalData.UserManager.Application.Services;
using DigitalData.UserManager.Application.Services.Options;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.UserManager.Infrastructure.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@ -19,8 +16,7 @@ namespace DigitalData.UserManager.Application
/// <typeparam name="TDbContext">The type of the DbContext to use for the repositories.</typeparam>
/// <param name="services">The IServiceCollection to which the services will be added.</param>
/// <returns>The updated IServiceCollection.</returns>
public static IServiceCollection AddUserManager<TDbContext>(this IServiceCollection services)
where TDbContext : DbContext, IUserManagerDbContext
public static IServiceCollection AddUserManager(this IServiceCollection services)
=> services
.AddAutoMapper(typeof(UserMappingProfile).Assembly)
.AddAutoMapper(typeof(GroupMappingProfile).Assembly)
@ -29,31 +25,13 @@ namespace DigitalData.UserManager.Application
.AddAutoMapper(typeof(ModuleOfUserMappingProfile).Assembly)
.AddAutoMapper(typeof(UserRepMappingProfile).Assembly)
.AddScoped<IUserRepository, UserRepository<TDbContext>>()
.AddScoped<IGroupRepository, GroupRepository<TDbContext>>()
.AddScoped<IGroupOfUserRepository, GroupOfUserRepository<TDbContext>>()
.AddScoped<IModuleRepository, ModuleRepository<TDbContext>>()
.AddScoped<IModuleOfUserRepository, ModuleOfUserRepository<TDbContext>>()
.AddScoped<IUserRepRepository, UserRepRepository<TDbContext>>()
.AddScoped<IClientUserRepository, ClientUserRepository<TDbContext>>()
.AddScoped<IUserService, UserService>()
.AddScoped<IGroupService, GroupService>()
.AddScoped<IGroupOfUserService, GroupOfUserService>()
.AddScoped<IModuleService, ModuleService>()
.AddScoped<IModuleOfUserService, ModuleOfUserService>()
.AddScoped<IUserRepService, UserRepService>();
/// <summary>
/// Adds the UserManager services and repositories to the specified <see cref="IServiceCollection"/>.
/// This method registers the necessary mappings, repositories, services and <see cref="UserManagerDbContext"/> for the UserManager.
/// </summary>
/// <param name="services">The IServiceCollection to which the services will be added.</param>
/// <returns>The updated IServiceCollection.</returns>
public static IServiceCollection AddUserManager(this IServiceCollection services, string connectionString)=> services
.AddDbContext<UserManagerDbContext>(options => options.UseSqlServer(connectionString).EnableSensitiveDataLogging())
.AddUserManager<UserManagerDbContext>();
public static IServiceCollection AddEncryptor(this IServiceCollection services, IConfiguration configuration)
{
services.AddSingleton<Encryptor>();

View File

@ -40,7 +40,6 @@
<ItemGroup>
<ProjectReference Include="..\DigitalData.UserManager.Domain\DigitalData.UserManager.Domain.csproj" />
<ProjectReference Include="..\DigitalData.UserManager.Infrastructure\DigitalData.UserManager.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -3,7 +3,7 @@ using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.GroupOfUser;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.UserManager.Application.Contracts.Repositories;
namespace DigitalData.UserManager.Application.Services
{

View File

@ -3,7 +3,7 @@ using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.Group;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.UserManager.Application.Contracts.Repositories;
using Microsoft.Extensions.Localization;
namespace DigitalData.UserManager.Application.Services

View File

@ -4,7 +4,7 @@ using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.ModuleOfUser;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.UserManager.Application.Contracts.Repositories;
namespace DigitalData.UserManager.Application.Services
{

View File

@ -3,7 +3,7 @@ using DigitalData.Core.Application;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.Module;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.UserManager.Application.Contracts.Repositories;
namespace DigitalData.UserManager.Application.Services
{

View File

@ -3,7 +3,7 @@ using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.UserRep;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.UserManager.Application.Contracts.Repositories;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;

View File

@ -3,7 +3,7 @@ using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.User;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.UserManager.Application.Contracts.Repositories;
using Microsoft.Extensions.Localization;
namespace DigitalData.UserManager.Application.Services

View File

@ -1,10 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Infrastructure.Contracts
{
public interface IClientUserRepository : ICRUDRepository<ClientUser, int>
{
Task<IEnumerable<ClientUser>> ReadAsync(bool readOnly = true, int? userId = null);
}
}

View File

@ -1,28 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Infrastructure.Contracts
{
public interface IGroupOfUserRepository : ICRUDRepository<GroupOfUser, int>
{
IQueryable<GroupOfUser> ReadByGroupId(int groupId);
Task<IEnumerable<GroupOfUser>> ReadByGroupUserIdAsync(int groupId, int userId);
Task<IEnumerable<GroupOfUser>> ReadAllAsyncWithGroup();
Task<IEnumerable<GroupOfUser>> ReadAllAsyncWithUser();
Task<IEnumerable<GroupOfUser>> ReadAllAsyncWithGroupAndUser();
Task<IEnumerable<GroupOfUser>> ReadByUsernameAsync(string username);
Task<IEnumerable<GroupOfUser>> ReadByUserIdAsync(int userId);
// merge all GroupOfUserRepository-methods conditionally under this method
Task<IEnumerable<GroupOfUser>> ReadAsync(
bool readOnly = true,
bool withGroup = true, bool withUser = true,
int? id = null, int? groupId = null, int? userId = null, string? username = null);
}
}

View File

@ -1,9 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Infrastructure.Contracts
{
public interface IGroupRepository : ICRUDRepository<Group, int>
{
}
}

View File

@ -1,14 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Infrastructure.Contracts
{
public interface IModuleOfUserRepository : ICRUDRepository<ModuleOfUser, int>
{
IQueryable<ModuleOfUser> ReadByModuleId(int moduleId);
Task<IEnumerable<ModuleOfUser>> ReadByModelUserIdAsync(int moduleId, int userId);
Task<IEnumerable<ModuleOfUser>> ReadByUserAsync(string username);
}
}

View File

@ -1,9 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Infrastructure.Contracts
{
public interface IModuleRepository : ICRUDRepository<Module, int>
{
}
}

View File

@ -1,22 +1,21 @@
using DigitalData.UserManager.Domain.Entities;
using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Contracts
namespace DigitalData.UserManager.Infrastructure.Contracts;
public interface IUserManagerDbContext
{
public interface IUserManagerDbContext
{
public DbSet<GroupOfUser> GroupOfUsers { get; }
public DbSet<GroupOfUser> GroupOfUsers { get; }
public DbSet<Group> Groups { get; }
public DbSet<Group> Groups { get; }
public DbSet<ModuleOfUser> ModuleOfUsers { get; }
public DbSet<ModuleOfUser> ModuleOfUsers { get; }
public DbSet<Module> Modules { get; }
public DbSet<Module> Modules { get; }
public DbSet<User> Users { get; }
public DbSet<User> Users { get; }
public DbSet<UserRep> UserReps { get; }
public DbSet<UserRep> UserReps { get; }
public DbSet<ClientUser> ClientUsers { get; }
}
public DbSet<ClientUser> ClientUsers { get; }
}

View File

@ -1,12 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Infrastructure.Contracts
{
public interface IUserRepRepository : ICRUDRepository<UserRep, int>
{
Task<IEnumerable<UserRep>> ReadAllAsync(
bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false,
int? userId = null, int? repUserId = null, int? groupId = null, int? repGroupId = null, bool readOnly = true);
}
}

View File

@ -1,18 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
namespace DigitalData.UserManager.Infrastructure.Contracts
{
public interface IUserRepository : ICRUDRepository<User, int>
{
Task<IEnumerable<User>> ReadByModuleIdAsync(int moduleId);
Task<IEnumerable<User>> ReadUnassignedByModuleIdAsync(int moduleId);
Task<IEnumerable<User>> ReadByGroupIdAsync(int groupId);
Task<IEnumerable<User>> ReadUnassignedByGroupIdAsync(int groupId);
Task<User?> ReadByUsernameAsync(string username);
}
}

View File

@ -0,0 +1,51 @@
using DigitalData.UserManager.Application;
using DigitalData.UserManager.Application.Contracts.Repositories;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.UserManager.Infrastructure.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace DigitalData.UserManager.Infrastructure;
public static class DependencyInjection
{
/// <summary>
/// Adds the UserManager repositories to the specified <see cref="IServiceCollection"/>.
/// This method registers the necessary repositories for the UserManager.
/// </summary>
/// <typeparam name="TDbContext">The type of the DbContext to use for the repositories.</typeparam>
/// <param name="services">The IServiceCollection to which the services will be added.</param>
/// <returns>The updated IServiceCollection.</returns>
public static IServiceCollection AddInfrastructureServices<TDbContext>(this IServiceCollection services)
where TDbContext : DbContext, IUserManagerDbContext
{
return services
.AddScoped<IUserRepository, UserRepository<TDbContext>>()
.AddScoped<IGroupRepository, GroupRepository<TDbContext>>()
.AddScoped<IGroupOfUserRepository, GroupOfUserRepository<TDbContext>>()
.AddScoped<IModuleRepository, ModuleRepository<TDbContext>>()
.AddScoped<IModuleOfUserRepository, ModuleOfUserRepository<TDbContext>>()
.AddScoped<IUserRepRepository, UserRepRepository<TDbContext>>()
.AddScoped<IClientUserRepository, ClientUserRepository<TDbContext>>();
}
/// <summary>
/// Adds the UserManager services and repositories to the specified <see cref="IServiceCollection"/>.
/// This method allows configuring the DbContext options using the provided <paramref name="optionsAction"/>.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to which the services will be added.</param>
/// <param name="optionsAction">An <see cref="Action{T}"/> to configure the <see cref="DbContextOptionsBuilder"/>.</param>
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, Action<DbContextOptionsBuilder> optionsAction) => services
.AddDbContext<UserManagerDbContext>(optionsAction)
.AddInfrastructureServices<UserManagerDbContext>();
/// <summary>
/// Adds the UserManager services and repositories to the specified <see cref="IServiceCollection"/>.
/// This method registers the necessary mappings, repositories, services and <see cref="UserManagerDbContext"/> for the UserManager.
/// </summary>
/// <param name="services">The IServiceCollection to which the services will be added.</param>
/// <returns>The updated IServiceCollection.</returns>
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, string connectionString) => services
.AddInfrastructureServices(options => options.UseSqlServer(connectionString).EnableSensitiveDataLogging());
}

View File

@ -36,6 +36,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DigitalData.UserManager.Application\DigitalData.UserManager.Application.csproj" />
<ProjectReference Include="..\DigitalData.UserManager.Domain\DigitalData.UserManager.Domain.csproj" />
</ItemGroup>

View File

@ -1,7 +1,8 @@
using DigitalData.Core.Infrastructure;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.UserManager.Application.Contracts.Repositories;
using Microsoft.EntityFrameworkCore;
using DigitalData.UserManager.Infrastructure.Contracts;
namespace DigitalData.UserManager.Infrastructure.Repositories
{

View File

@ -2,6 +2,7 @@
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.Core.Infrastructure;
using Microsoft.EntityFrameworkCore;
using DigitalData.UserManager.Application.Contracts.Repositories;
namespace DigitalData.UserManager.Infrastructure.Repositories
{

View File

@ -1,4 +1,5 @@
using DigitalData.Core.Infrastructure;
using DigitalData.UserManager.Application.Contracts.Repositories;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.EntityFrameworkCore;

View File

@ -1,32 +1,32 @@
using DigitalData.Core.Infrastructure;
using DigitalData.UserManager.Application.Contracts.Repositories;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Repositories
namespace DigitalData.UserManager.Infrastructure.Repositories;
public class ModuleOfUserRepository<TDbContext> : CRUDRepository<ModuleOfUser, int, TDbContext>, IModuleOfUserRepository
where TDbContext : DbContext, IUserManagerDbContext
{
public class ModuleOfUserRepository<TDbContext> : CRUDRepository<ModuleOfUser, int, TDbContext>, IModuleOfUserRepository
where TDbContext : DbContext, IUserManagerDbContext
public ModuleOfUserRepository(TDbContext dbContext) : base(dbContext, dbContext.ModuleOfUsers)
{
public ModuleOfUserRepository(TDbContext dbContext) : base(dbContext, dbContext.ModuleOfUsers)
{
}
private IQueryable<ModuleOfUser> ReadByUser(string username)
{
return _dbSet.Where(mou => mou.User!.Username == username).Include(mou => mou.Module);
}
public IQueryable<ModuleOfUser> ReadByModuleId(int moduleId)
{
return _dbSet.Where(mou => mou.ModuleId == moduleId);
}
public async Task<IEnumerable<ModuleOfUser>> ReadByModelUserIdAsync(int moduleId, int userId)
{
return await _dbSet.Where(mou => mou.ModuleId == moduleId && mou.UserId == userId).ToListAsync();
}
public async Task<IEnumerable<ModuleOfUser>> ReadByUserAsync(string username) => await ReadByUser(username).ToListAsync();
}
private IQueryable<ModuleOfUser> ReadByUser(string username)
{
return _dbSet.Where(mou => mou.User!.Username == username).Include(mou => mou.Module);
}
public IQueryable<ModuleOfUser> ReadByModuleId(int moduleId)
{
return _dbSet.Where(mou => mou.ModuleId == moduleId);
}
public async Task<IEnumerable<ModuleOfUser>> ReadByModelUserIdAsync(int moduleId, int userId)
{
return await _dbSet.Where(mou => mou.ModuleId == moduleId && mou.UserId == userId).ToListAsync();
}
public async Task<IEnumerable<ModuleOfUser>> ReadByUserAsync(string username) => await ReadByUser(username).ToListAsync();
}

View File

@ -1,15 +1,15 @@
using DigitalData.Core.Infrastructure;
using DigitalData.UserManager.Application.Contracts.Repositories;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Repositories
namespace DigitalData.UserManager.Infrastructure.Repositories;
public class ModuleRepository<TDbContext> : CRUDRepository<Module, int, TDbContext>, IModuleRepository
where TDbContext : DbContext, IUserManagerDbContext
{
public class ModuleRepository<TDbContext> : CRUDRepository<Module, int, TDbContext>, IModuleRepository
where TDbContext : DbContext, IUserManagerDbContext
public ModuleRepository(TDbContext dbContext) : base(dbContext, dbContext.Modules)
{
public ModuleRepository(TDbContext dbContext) : base(dbContext, dbContext.Modules)
{
}
}
}

View File

@ -1,48 +1,48 @@
using DigitalData.Core.Infrastructure;
using DigitalData.UserManager.Application.Contracts.Repositories;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Repositories
namespace DigitalData.UserManager.Infrastructure.Repositories;
public class UserRepRepository<TDbContext> : CRUDRepository<UserRep, int, TDbContext>, IUserRepRepository
where TDbContext : DbContext, IUserManagerDbContext
{
public class UserRepRepository<TDbContext> : CRUDRepository<UserRep, int, TDbContext>, IUserRepRepository
where TDbContext : DbContext, IUserManagerDbContext
public UserRepRepository(TDbContext dbContext) : base(dbContext, dbContext.UserReps)
{
public UserRepRepository(TDbContext dbContext) : base(dbContext, dbContext.UserReps)
{
}
}
public async Task<IEnumerable<UserRep>> ReadAllAsync(
bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false,
int? userId = null, int? repUserId = null, int? groupId = null, int? repGroupId = null, bool readOnly = true)
{
var query = readOnly ? _dbSet.AsNoTracking() : _dbSet.AsQueryable();
public async Task<IEnumerable<UserRep>> ReadAllAsync(
bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false,
int? userId = null, int? repUserId = null, int? groupId = null, int? repGroupId = null, bool readOnly = true)
{
var query = readOnly ? _dbSet.AsNoTracking() : _dbSet.AsQueryable();
if (withUser)
query = query.Include(ur => ur.User);
if (withUser)
query = query.Include(ur => ur.User);
if (withRepGroup)
query = query.Include(ur => ur.RepGroup);
if (withRepGroup)
query = query.Include(ur => ur.RepGroup);
if (withGroup)
query = query.Include(ur => ur.Group);
if (withGroup)
query = query.Include(ur => ur.Group);
if (withRepUser)
query = query.Include(ur => ur.RepUser);
if (withRepUser)
query = query.Include(ur => ur.RepUser);
if (userId is not null)
query = query.Where(ur => ur.UserId == userId);
if (userId is not null)
query = query.Where(ur => ur.UserId == userId);
if (repUserId is not null)
query = query.Where(ur => ur.RepUserId == repUserId);
if (repUserId is not null)
query = query.Where(ur => ur.RepUserId == repUserId);
if (groupId is not null)
query = query.Where(ur => ur.GroupId == groupId);
if (groupId is not null)
query = query.Where(ur => ur.GroupId == groupId);
if (repGroupId is not null)
query = query.Where(ur => ur.RepGroupId == repGroupId);
if (repGroupId is not null)
query = query.Where(ur => ur.RepGroupId == repGroupId);
return await query.ToListAsync();
}
return await query.ToListAsync();
}
}

View File

@ -1,4 +1,5 @@
using DigitalData.Core.Infrastructure;
using DigitalData.UserManager.Application.Contracts.Repositories;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.EntityFrameworkCore;