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

63 lines
1.8 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 Update(Folder folder)
{
if (folder.IsRelativeRoot()) // TODO: triple check
{
var original = GetFolderById(folder.Id);
if (original is null)
return false;
folder.ParentId = original.ParentId;
}
return Connection.InsertOrReplace(folder) > 0;
}
public static Boolean Update(Installation installation)
{
if (installation.IsRelativeRoot()) // TODO: triple check
{
var original = GetInstallationById(installation.Id);
if (original is null)
return false;
installation.ParentId = original.ParentId;
}
return Connection.InsertOrReplace(installation) > 0;
}
public static Boolean Update(User user)
{
var originalUser = GetUserById(user.Id);
return originalUser is not null
&& user.Id == originalUser.Id // these columns must not be modified!
&& user.ParentId == originalUser.ParentId
&& user.Email == originalUser.Email
&& Connection.InsertOrReplace(user) > 0;
}
public static Boolean Update(this Session session)
{
#pragma warning disable CS0618
var originalSession = GetSessionById(session.Id);
#pragma warning restore CS0618
return originalSession is not null
&& session.Token == originalSession.Token // these columns must not be modified!
&& session.UserId == originalSession.UserId
&& Connection.InsertOrReplace(session) > 0;
}
}