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

81 lines
2.3 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)
{
2023-09-15 11:34:28 +00:00
var deleteSuccess= RunTransaction(DeleteFolderAndAllItsDependencies);
if (deleteSuccess)
{
BackupDatabase();
}
return deleteSuccess;
2023-03-15 13:38:06 +00:00
Boolean DeleteFolderAndAllItsDependencies()
{
return folder
2023-09-15 11:34:28 +00:00
.DescendantFoldersAndSelf()
2023-03-15 13:38:06 +00:00
.All(DeleteDescendantFolderAndItsDependencies);
}
Boolean DeleteDescendantFolderAndItsDependencies(Folder f)
{
FolderAccess .Delete(r => r.FolderId == f.Id);
Installations.Delete(r => r.ParentId == f.Id);
2023-09-08 07:45:56 +00:00
var delete = Folders.Delete(r => r.Id == f.Id);
2023-09-15 11:34:28 +00:00
return delete>0;
2023-03-15 13:38:06 +00:00
}
}
public static Boolean Delete(Installation installation)
{
2023-09-08 07:45:56 +00:00
var deleteSuccess = RunTransaction(DeleteInstallationAndItsDependencies);
if (deleteSuccess)
BackupDatabase();
return deleteSuccess;
2023-03-15 13:38:06 +00:00
Boolean DeleteInstallationAndItsDependencies()
{
InstallationAccess.Delete(i => i.InstallationId == installation.Id);
2023-09-15 11:34:28 +00:00
OrderNumber2Installation.Delete(i => i.InstallationId == installation.Id);
2023-09-08 07:45:56 +00:00
return Installations.Delete(i => i.Id == installation.Id) > 0;
2023-03-15 13:38:06 +00:00
}
}
public static Boolean Delete(User user)
{
2023-09-08 07:45:56 +00:00
var deleteSuccess = RunTransaction(DeleteUserAndHisDependencies);
if (deleteSuccess)
BackupDatabase();
return deleteSuccess;
2023-03-15 13:38:06 +00:00
Boolean DeleteUserAndHisDependencies()
{
FolderAccess .Delete(u => u.UserId == user.Id);
InstallationAccess.Delete(u => u.UserId == user.Id);
2023-03-15 13:38:06 +00:00
2023-09-08 07:45:56 +00:00
return Users.Delete(u => u.Id == user.Id) > 0;
2023-03-15 13:38:06 +00:00
}
}
#pragma warning disable CS0618
// private!!
private static Boolean Delete(Session session)
{
var delete = Sessions.Delete(s => s.Id == session.Id) > 0;
2023-09-08 07:45:56 +00:00
if (delete)
BackupDatabase();
return delete;
2023-03-15 13:38:06 +00:00
}
}