Innovenergy_trunk/csharp/App/Backend/Database/Delete.cs

63 lines
1.7 KiB
C#
Raw Normal View History

2023-03-15 13:38:06 +00:00
using InnovEnergy.App.Backend.DataTypes;
using InnovEnergy.App.Backend.DataTypes.Methods;
using InnovEnergy.App.Backend.Relations;
namespace InnovEnergy.App.Backend.Database;
public static partial class Db
{
public static Boolean Delete(Folder folder)
{
return RunTransaction(DeleteFolderAndAllItsDependencies);
Boolean DeleteFolderAndAllItsDependencies()
{
return folder
.DescendantFolders()
.All(DeleteDescendantFolderAndItsDependencies);
}
Boolean DeleteDescendantFolderAndItsDependencies(Folder f)
{
FolderAccess .Delete(r => r.FolderId == f.Id);
2023-03-15 13:38:06 +00:00
Installations.Delete(r => r.ParentId == f.Id);
return Folders.Delete(r => r.Id == f.Id) > 0;
}
}
public static Boolean Delete(Installation installation)
{
return RunTransaction(DeleteInstallationAndItsDependencies);
Boolean DeleteInstallationAndItsDependencies()
{
InstallationAccess.Delete(i => i.InstallationId == installation.Id);
2023-03-15 13:38:06 +00:00
return Installations.Delete(i => i.Id == installation.Id) > 0;
}
}
public static Boolean Delete(User user)
{
return RunTransaction(DeleteUserAndHisDependencies);
Boolean DeleteUserAndHisDependencies()
{
FolderAccess .Delete(u => u.UserId == user.Id);
InstallationAccess.Delete(u => u.UserId == user.Id);
2023-03-15 13:38:06 +00:00
return Users.Delete(u => u.Id == user.Id) > 0;
}
}
#pragma warning disable CS0618
// private!!
private static Boolean Delete(Session session)
{
return Sessions.Delete(s => s.Id == session.Id) > 0;
}
}