From 50e01e6c8cec0e7bd48d6a6a0d1c2bf459fe2774 Mon Sep 17 00:00:00 2001 From: Kim Date: Fri, 8 Sep 2023 09:45:56 +0200 Subject: [PATCH] fixed deletion --- .../Backend/DataTypes/Methods/Installation.cs | 2 +- csharp/App/Backend/Database/Delete.cs | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/csharp/App/Backend/DataTypes/Methods/Installation.cs b/csharp/App/Backend/DataTypes/Methods/Installation.cs index 3ec874011..76d6ac88b 100644 --- a/csharp/App/Backend/DataTypes/Methods/Installation.cs +++ b/csharp/App/Backend/DataTypes/Methods/Installation.cs @@ -76,7 +76,7 @@ public static class InstallationMethods var deletedInstallation = new DeletedInstallation(); foreach (var property in installation.GetType().GetProperties()) { - property.SetValue(deletedInstallation ,property.GetValue(installation)); + property.SetValue(deletedInstallation, property.GetValue(installation)); } return deletedInstallation; diff --git a/csharp/App/Backend/Database/Delete.cs b/csharp/App/Backend/Database/Delete.cs index a99229584..55ff12f84 100644 --- a/csharp/App/Backend/Database/Delete.cs +++ b/csharp/App/Backend/Database/Delete.cs @@ -23,37 +23,42 @@ public static partial class Db { FolderAccess .Delete(r => r.FolderId == f.Id); Installations.Delete(r => r.ParentId == f.Id); - var delete = Folders.Delete(r => r.Id == f.Id); - BackupDatabase(); - return delete > 0; + var delete = Folders.Delete(r => r.Id == f.Id); + var deleteSuccess = delete > 0; + if (deleteSuccess) + BackupDatabase(); + return deleteSuccess; } } public static Boolean Delete(Installation installation) { - return RunTransaction(DeleteInstallationAndItsDependencies); - + var deleteSuccess = RunTransaction(DeleteInstallationAndItsDependencies); + if (deleteSuccess) + BackupDatabase(); + return deleteSuccess; + + Boolean DeleteInstallationAndItsDependencies() { InstallationAccess.Delete(i => i.InstallationId == installation.Id); - var delete = Installations.Delete(i => i.Id == installation.Id); - BackupDatabase(); - return delete > 0; + return Installations.Delete(i => i.Id == installation.Id) > 0; } } public static Boolean Delete(User user) { - return RunTransaction(DeleteUserAndHisDependencies); + var deleteSuccess = RunTransaction(DeleteUserAndHisDependencies); + if (deleteSuccess) + BackupDatabase(); + return deleteSuccess; Boolean DeleteUserAndHisDependencies() { FolderAccess .Delete(u => u.UserId == user.Id); InstallationAccess.Delete(u => u.UserId == user.Id); - var delete = Users.Delete(u => u.Id == user.Id); - BackupDatabase(); - return delete > 0; + return Users.Delete(u => u.Id == user.Id) > 0; } } @@ -64,7 +69,8 @@ public static partial class Db private static Boolean Delete(Session session) { var delete = Sessions.Delete(s => s.Id == session.Id) > 0; - BackupDatabase(); + if (delete) + BackupDatabase(); return delete; } } \ No newline at end of file