refactor: ClientUser-Repository-Abhängigkeit hinzugefügt und DeleteAsync in UserRepository verbessert
This commit is contained in:
parent
2a4358a7c7
commit
80a3f96404
@ -35,6 +35,7 @@ namespace DigitalData.UserManager.Application
|
||||
.AddScoped<IModuleRepository, ModuleRepository<TDbContext>>()
|
||||
.AddScoped<IModuleOfUserRepository, ModuleOfUserRepository<TDbContext>>()
|
||||
.AddScoped<IUserRepRepository, UserRepRepository<TDbContext>>()
|
||||
.AddScoped<IClientUserRepository, ClientUserRepository<TDbContext>>()
|
||||
|
||||
.AddScoped<IUserService, UserService>()
|
||||
.AddScoped<IGroupService, GroupService>()
|
||||
|
||||
@ -1,11 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using DigitalData.Core.Abstractions;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace DigitalData.UserManager.Domain.Entities
|
||||
{
|
||||
[Table("TBDD_CLIENT_USER", Schema = "dbo")]
|
||||
public class ClientUser : BaseEntity
|
||||
public class ClientUser : IUnique<int>
|
||||
{
|
||||
[Column("GUID")]
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[Column("USER_ID")]
|
||||
public int UserId { get; init; }
|
||||
@ -16,5 +23,13 @@ namespace DigitalData.UserManager.Domain.Entities
|
||||
|
||||
[Column("COMMENT")]
|
||||
public string? Comment { get; init; }
|
||||
|
||||
[StringLength(50)]
|
||||
[Column("ADDED_WHO")]
|
||||
public string? AddedWho { get; set; }
|
||||
|
||||
[Column("ADDED_WHEN", TypeName = "datetime")]
|
||||
[DefaultValue("GETDATE()")]
|
||||
public DateTime AddedWhen { get; set; } = DateTime.Now;
|
||||
}
|
||||
}
|
||||
@ -16,5 +16,7 @@ namespace DigitalData.UserManager.Infrastructure.Contracts
|
||||
public DbSet<User> Users { get; }
|
||||
|
||||
public DbSet<UserRep> UserReps { get; }
|
||||
|
||||
public DbSet<ClientUser> ClientUsers { get; }
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,7 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
public class ClientUserRepository<TDbContext> : CRUDRepository<ClientUser, int, TDbContext>, IClientUserRepository
|
||||
where TDbContext : DbContext, IUserManagerDbContext
|
||||
{
|
||||
public ClientUserRepository(TDbContext dbContext) : base(dbContext, dbContext.Set<ClientUser>())
|
||||
public ClientUserRepository(TDbContext dbContext) : base(dbContext, dbContext.ClientUsers)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -25,11 +25,11 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
if (gou_list.Any())
|
||||
_dbContext.RemoveRange(gou_list);
|
||||
|
||||
var uRep_list = await _uRepRepo.ReadAllAsync(groupId: group.Id);
|
||||
var uRep_list = await _uRepRepo.ReadAllAsync(readOnly: false, groupId: group.Id);
|
||||
if (uRep_list.Any())
|
||||
_dbContext.RemoveRange(uRep_list);
|
||||
|
||||
uRep_list = await _uRepRepo.ReadAllAsync(repGroupId: group.Id);
|
||||
uRep_list = await _uRepRepo.ReadAllAsync(readOnly: false, repGroupId: group.Id);
|
||||
if (uRep_list.Any())
|
||||
_dbContext.RemoveRange(uRep_list);
|
||||
|
||||
|
||||
@ -14,11 +14,14 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
|
||||
private readonly IUserRepRepository _uRepRepo;
|
||||
|
||||
public UserRepository(TDbContext dbContext, IModuleOfUserRepository moduleOfUserRepo, IGroupOfUserRepository groupOfUserRepo, IUserRepRepository userRepRepository) : base(dbContext, dbContext.Users)
|
||||
private readonly IClientUserRepository _cUserRepo;
|
||||
|
||||
public UserRepository(TDbContext dbContext, IModuleOfUserRepository moduleOfUserRepo, IGroupOfUserRepository groupOfUserRepo, IUserRepRepository userRepRepository, IClientUserRepository clientUserRepository) : base(dbContext, dbContext.Users)
|
||||
{
|
||||
_moduleOfUserRepo = moduleOfUserRepo;
|
||||
_groupOfUserRepo = groupOfUserRepo;
|
||||
_uRepRepo = userRepRepository;
|
||||
_cUserRepo = clientUserRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<User>> ReadByModuleIdAsync(int moduleId)
|
||||
@ -61,14 +64,18 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
if (gou.Any())
|
||||
_dbContext.RemoveRange(gou);
|
||||
|
||||
var uRep_list = await _uRepRepo.ReadAllAsync(userId: user.Id);
|
||||
var uRep_list = await _uRepRepo.ReadAllAsync(readOnly: false, userId: user.Id);
|
||||
if (uRep_list.Any())
|
||||
_dbContext.RemoveRange(uRep_list);
|
||||
|
||||
uRep_list = await _uRepRepo.ReadAllAsync(repUserId: user.Id);
|
||||
uRep_list = await _uRepRepo.ReadAllAsync(readOnly: false, repUserId: user.Id);
|
||||
if (uRep_list.Any())
|
||||
_dbContext.RemoveRange(uRep_list);
|
||||
|
||||
var cu_list = await _cUserRepo.ReadAsync(readOnly: false, userId: user.Id);
|
||||
if (cu_list.Any())
|
||||
_dbContext.RemoveRange(cu_list);
|
||||
|
||||
return await base.DeleteAsync(user);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,6 +18,8 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
|
||||
public DbSet<UserRep> UserReps { get; set; }
|
||||
|
||||
public DbSet<ClientUser> ClientUsers { get; set; }
|
||||
|
||||
public UserManagerDbContext(DbContextOptions<UserManagerDbContext> options) : base(options)
|
||||
{
|
||||
GroupOfUsers = Set<GroupOfUser>();
|
||||
@ -26,6 +28,7 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
Modules = Set<Module>();
|
||||
Users = Set<User>();
|
||||
UserReps = Set<UserRep>();
|
||||
ClientUsers = Set<ClientUser>();
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user