2023-03-15 13:38:06 +00:00
|
|
|
using InnovEnergy.App.Backend.DataTypes;
|
|
|
|
using InnovEnergy.App.Backend.DataTypes.Methods;
|
|
|
|
using InnovEnergy.App.Backend.Relations;
|
2024-06-11 12:31:08 +00:00
|
|
|
using Microsoft.AspNetCore.Authentication.OAuth.Claims;
|
2023-03-15 13:38:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace InnovEnergy.App.Backend.Database;
|
|
|
|
|
|
|
|
|
|
|
|
public static partial class Db
|
|
|
|
{
|
2024-07-02 14:53:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
private static void Backup()
|
|
|
|
{
|
|
|
|
_backupCounter++;
|
|
|
|
if (_backupCounter > 100)
|
|
|
|
{
|
|
|
|
_backupCounter = 0;
|
|
|
|
BackupDatabase();
|
|
|
|
}
|
|
|
|
}
|
2023-03-15 13:38:06 +00:00
|
|
|
public static Boolean Delete(Folder folder)
|
|
|
|
{
|
2023-09-15 11:34:28 +00:00
|
|
|
var deleteSuccess= RunTransaction(DeleteFolderAndAllItsDependencies);
|
|
|
|
if (deleteSuccess)
|
|
|
|
{
|
2024-07-02 14:53:51 +00:00
|
|
|
Backup();
|
2023-09-15 11:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2023-03-16 10:16:23 +00:00
|
|
|
FolderAccess .Delete(r => r.FolderId == f.Id);
|
2023-07-13 11:23:05 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2023-11-15 16:22:42 +00:00
|
|
|
|
|
|
|
public static Boolean Delete(Error errorToDelete)
|
|
|
|
{
|
|
|
|
var deleteSuccess = RunTransaction(DeleteError);
|
2024-07-02 14:53:51 +00:00
|
|
|
|
2023-11-15 16:22:42 +00:00
|
|
|
if (deleteSuccess)
|
2024-07-02 14:53:51 +00:00
|
|
|
Backup();
|
2023-11-15 16:22:42 +00:00
|
|
|
return deleteSuccess;
|
|
|
|
|
|
|
|
|
|
|
|
Boolean DeleteError()
|
|
|
|
{
|
|
|
|
return Errors.Delete(error => error.Id == errorToDelete.Id) >0;
|
|
|
|
}
|
2024-06-11 12:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Boolean Delete(UserAction actionToDelete)
|
|
|
|
{
|
|
|
|
var deleteSuccess = RunTransaction(DeleteAction);
|
|
|
|
if (deleteSuccess)
|
2024-07-02 14:53:51 +00:00
|
|
|
Backup();
|
2024-06-11 12:31:08 +00:00
|
|
|
return deleteSuccess;
|
|
|
|
|
|
|
|
|
|
|
|
Boolean DeleteAction()
|
|
|
|
{
|
|
|
|
return UserActions.Delete(action => action.Id == actionToDelete.Id) >0;
|
|
|
|
}
|
2023-11-15 16:22:42 +00:00
|
|
|
}
|
2023-11-20 16:29:45 +00:00
|
|
|
|
|
|
|
public static Boolean Delete(Warning warningToDelete)
|
|
|
|
{
|
|
|
|
var deleteSuccess = RunTransaction(DeleteWarning);
|
|
|
|
if (deleteSuccess)
|
2024-07-02 14:53:51 +00:00
|
|
|
Backup();
|
2023-11-20 16:29:45 +00:00
|
|
|
return deleteSuccess;
|
|
|
|
|
|
|
|
|
|
|
|
Boolean DeleteWarning()
|
|
|
|
{
|
|
|
|
return Warnings.Delete(error => error.Id == warningToDelete.Id) >0;
|
|
|
|
}
|
|
|
|
}
|
2024-06-26 15:05:27 +00:00
|
|
|
|
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)
|
2024-07-02 14:53:51 +00:00
|
|
|
Backup();
|
2023-09-08 07:45:56 +00:00
|
|
|
return deleteSuccess;
|
|
|
|
|
|
|
|
|
2023-03-15 13:38:06 +00:00
|
|
|
Boolean DeleteInstallationAndItsDependencies()
|
|
|
|
{
|
2024-04-16 11:57:04 +00:00
|
|
|
if (installation.Product == 0)
|
|
|
|
{
|
|
|
|
InstallationAccess.Delete(i => i.InstallationId == installation.Id);
|
|
|
|
OrderNumber2Installation.Delete(i => i.InstallationId == installation.Id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-09-08 07:45:56 +00:00
|
|
|
return Installations.Delete(i => i.Id == installation.Id) > 0;
|
2024-04-16 11:57:04 +00:00
|
|
|
|
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)
|
2024-07-02 14:53:51 +00:00
|
|
|
Backup();
|
2023-09-08 07:45:56 +00:00
|
|
|
return deleteSuccess;
|
2023-03-15 13:38:06 +00:00
|
|
|
|
|
|
|
Boolean DeleteUserAndHisDependencies()
|
|
|
|
{
|
2023-03-16 10:16:23 +00:00
|
|
|
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)
|
|
|
|
{
|
2023-07-13 11:23:05 +00:00
|
|
|
var delete = Sessions.Delete(s => s.Id == session.Id) > 0;
|
2023-09-08 07:45:56 +00:00
|
|
|
if (delete)
|
2024-07-02 14:53:51 +00:00
|
|
|
Backup();
|
2023-07-13 11:23:05 +00:00
|
|
|
return delete;
|
2023-03-15 13:38:06 +00:00
|
|
|
}
|
2023-10-23 11:08:09 +00:00
|
|
|
|
|
|
|
public static void Delete(OrderNumber2Installation relation)
|
|
|
|
{
|
|
|
|
OrderNumber2Installation.Delete(s => s.InstallationId == relation.InstallationId && s.OrderNumber == relation.OrderNumber);
|
|
|
|
}
|
2023-03-15 13:38:06 +00:00
|
|
|
}
|