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

70 lines
2.0 KiB
C#

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);
Installations.Delete(r => r.ParentId == f.Id);
var delete = Folders.Delete(r => r.Id == f.Id);
BackupDatabase();
return delete > 0;
}
}
public static Boolean Delete(Installation installation)
{
return RunTransaction(DeleteInstallationAndItsDependencies);
Boolean DeleteInstallationAndItsDependencies()
{
InstallationAccess.Delete(i => i.InstallationId == installation.Id);
var delete = Installations.Delete(i => i.Id == installation.Id);
BackupDatabase();
return delete > 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);
var delete = Users.Delete(u => u.Id == user.Id);
BackupDatabase();
return delete > 0;
}
}
#pragma warning disable CS0618
// private!!
private static Boolean Delete(Session session)
{
var delete = Sessions.Delete(s => s.Id == session.Id) > 0;
BackupDatabase();
return delete;
}
}