feat: erweitere GroupRepository mit Unterstützung für das Löschen verwandter Entitäten
- Abhängigkeiten IGroupOfUserRepository und IUserRepRepository zum GroupRepository-Konstruktor hinzugefügt. - DeleteAsync aktualisiert, um verwandte Entitäten in den GroupOfUser- und UserRep-Tabellen zu löschen, bevor die Gruppe entfernt wird.
This commit is contained in:
parent
e80ec2cf8d
commit
9f99bb0bc9
@ -8,8 +8,27 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
public class GroupRepository<TDbContext> : CRUDRepository<Group, int, TDbContext>, IGroupRepository
|
||||
where TDbContext : DbContext, IUserManagerDbContext
|
||||
{
|
||||
public GroupRepository(TDbContext dbContext) : base(dbContext, dbContext.Groups)
|
||||
private readonly IGroupOfUserRepository _gouRepo;
|
||||
|
||||
private readonly IUserRepRepository _uRepRepo;
|
||||
|
||||
public GroupRepository(TDbContext dbContext, IGroupOfUserRepository gouRepo, IUserRepRepository userRepRepository) : base(dbContext, dbContext.Groups)
|
||||
{
|
||||
_gouRepo = gouRepo;
|
||||
_uRepRepo = userRepRepository;
|
||||
}
|
||||
|
||||
public override async Task<bool> DeleteAsync(Group group)
|
||||
{
|
||||
var gou_list = await _gouRepo.ReadAsync(readOnly: false, groupId: group.Id);
|
||||
if (gou_list.Any())
|
||||
_dbContext.RemoveRange(gou_list);
|
||||
|
||||
var ur_list = await _uRepRepo.ReadAllAsync(groupId: group.Id);
|
||||
if (ur_list.Any())
|
||||
_dbContext.RemoveRange(ur_list);
|
||||
|
||||
return await base.DeleteAsync(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user