2023-03-15 13:38:06 +00:00
|
|
|
using InnovEnergy.App.Backend.DataTypes;
|
|
|
|
namespace InnovEnergy.App.Backend.Database;
|
|
|
|
|
|
|
|
|
|
|
|
public static partial class Db
|
|
|
|
{
|
2024-12-16 14:03:27 +00:00
|
|
|
//We can execute the updates manually for each table, but we prefer the abstract way using Connection.Update method
|
|
|
|
//We pass an object as an argument and the Connection will connect this object with the corresponding table.
|
|
|
|
//The update is being done based on the primary id of the object.
|
|
|
|
|
2023-07-13 11:23:05 +00:00
|
|
|
private static Boolean Update(Object obj)
|
|
|
|
{
|
|
|
|
var success = Connection.Update(obj) > 0;
|
2024-07-02 14:53:51 +00:00
|
|
|
if(success) Backup();
|
2023-07-13 11:23:05 +00:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2023-03-15 13:38:06 +00:00
|
|
|
public static Boolean Update(Folder folder)
|
|
|
|
{
|
2023-07-13 11:23:05 +00:00
|
|
|
return Update(obj: folder);
|
2023-03-15 13:38:06 +00:00
|
|
|
}
|
2023-11-22 08:35:29 +00:00
|
|
|
|
|
|
|
public static Boolean Update(Error error)
|
|
|
|
{
|
|
|
|
return Update(obj: error);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Boolean Update(Warning warning)
|
|
|
|
{
|
|
|
|
return Update(obj: warning);
|
|
|
|
}
|
2023-03-15 13:38:06 +00:00
|
|
|
|
|
|
|
public static Boolean Update(Installation installation)
|
|
|
|
{
|
2023-07-13 11:23:05 +00:00
|
|
|
return Update(obj: installation);
|
2023-03-15 13:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Boolean Update(User user)
|
|
|
|
{
|
|
|
|
var originalUser = GetUserById(user.Id);
|
2023-04-06 06:32:47 +00:00
|
|
|
if (originalUser is null) return false;
|
|
|
|
|
|
|
|
// these columns must not be modified!
|
|
|
|
user.ParentId = originalUser.ParentId;
|
|
|
|
user.Name = originalUser.Name;
|
|
|
|
|
2023-07-13 11:23:05 +00:00
|
|
|
return Update(obj: user);
|
2023-03-15 13:38:06 +00:00
|
|
|
}
|
2024-12-16 14:03:27 +00:00
|
|
|
|
|
|
|
public static void UpdateAction(UserAction updatedAction)
|
|
|
|
{
|
|
|
|
var existingAction = UserActions.FirstOrDefault(action => action.Id == updatedAction.Id);
|
|
|
|
|
|
|
|
if (existingAction != null)
|
|
|
|
{
|
|
|
|
Update(updatedAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-15 13:38:06 +00:00
|
|
|
}
|