75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
using InnovEnergy.App.Backend.DataTypes;
|
|
namespace InnovEnergy.App.Backend.Database;
|
|
|
|
|
|
public static partial class Db
|
|
{
|
|
//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.
|
|
|
|
private static Boolean Update(Object obj)
|
|
{
|
|
var success = Connection.Update(obj) > 0;
|
|
if(success) Backup();
|
|
return success;
|
|
}
|
|
|
|
public static Boolean Update(Folder folder)
|
|
{
|
|
return Update(obj: folder);
|
|
}
|
|
|
|
public static Boolean Update(Error error)
|
|
{
|
|
return Update(obj: error);
|
|
}
|
|
|
|
public static Boolean Update(Warning warning)
|
|
{
|
|
return Update(obj: warning);
|
|
}
|
|
|
|
public static Boolean Update(Installation installation)
|
|
{
|
|
return Update(obj: installation);
|
|
}
|
|
|
|
public static Boolean Update(User user)
|
|
{
|
|
var originalUser = GetUserById(user.Id);
|
|
if (originalUser is null) return false;
|
|
|
|
// ParentId must not be modified via this method
|
|
user.ParentId = originalUser.ParentId;
|
|
|
|
return Update(obj: user);
|
|
}
|
|
|
|
public static void UpdateAction(UserAction updatedAction)
|
|
{
|
|
var existingAction = UserActions.FirstOrDefault(action => action.Id == updatedAction.Id);
|
|
|
|
if (existingAction != null)
|
|
{
|
|
Update(updatedAction);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates ONLY the Status column for an installation.
|
|
/// This avoids a full-row overwrite that can race with TestingMode changes.
|
|
/// </summary>
|
|
public static Boolean UpdateInstallationStatus(Int64 installationId, int status)
|
|
{
|
|
var rows = Connection.Execute(
|
|
"UPDATE Installation SET Status = ? WHERE Id = ?",
|
|
status, installationId);
|
|
if (rows > 0) Backup();
|
|
return rows > 0;
|
|
}
|
|
|
|
// Ticket system
|
|
public static Boolean Update(Ticket ticket) => Update(obj: ticket);
|
|
public static Boolean Update(TicketAiDiagnosis diagnosis) => Update(obj: diagnosis);
|
|
} |