From ee9190447fb843cbe924e7d46f08f36db7bb9abc Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Sun, 29 Oct 2023 17:51:47 +0100 Subject: [PATCH] Fixed some user deletion issues --- Moonlight/App/Services/ServiceManage/ServiceAdminService.cs | 2 +- Moonlight/App/Services/Users/UserDeleteService.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Moonlight/App/Services/ServiceManage/ServiceAdminService.cs b/Moonlight/App/Services/ServiceManage/ServiceAdminService.cs index d189f24..2fe7b46 100644 --- a/Moonlight/App/Services/ServiceManage/ServiceAdminService.cs +++ b/Moonlight/App/Services/ServiceManage/ServiceAdminService.cs @@ -75,7 +75,7 @@ public class ServiceAdminService await Actions[service.Product.Type].Delete(scope.ServiceProvider, service); - foreach (var share in service.Shares) + foreach (var share in service.Shares.ToArray()) { serviceShareRepo.Delete(share); } diff --git a/Moonlight/App/Services/Users/UserDeleteService.cs b/Moonlight/App/Services/Users/UserDeleteService.cs index b3dd875..c9ce8da 100644 --- a/Moonlight/App/Services/Users/UserDeleteService.cs +++ b/Moonlight/App/Services/Users/UserDeleteService.cs @@ -104,6 +104,9 @@ public class UserDeleteService TransactionRepository.Delete(transaction); // User - UserRepository.Delete(user); + + // We need to use this in order to entity framework not crashing because of the previous deleted data + var userToDelete = UserRepository.Get().First(x => x.Id == user.Id); + UserRepository.Delete(userToDelete); } } \ No newline at end of file