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

56 lines
1.5 KiB
C#

using InnovEnergy.App.Backend.Model;
using SQLite;
namespace InnovEnergy.App.Backend.Database;
public static partial class Db
{
private static TableQuery<Installation> Installations => _Db.Table<Installation>();
public static Int32 NbInstallations => Installations.Count();
public static Installation? GetInstallationById(Int64 id) => Installations
.FirstOrDefault(u => u.Id == id);
private static IEnumerable<Folder> Ancestors(Installation installation)
{
var parentFolder = GetParent(installation);
return parentFolder is null
? Enumerable.Empty<Folder>()
: Ancestors(parentFolder);
}
public static Folder? GetParent(Installation installation)
{
return IsRoot(installation)
? null
: GetFolderById(installation.ParentId);
}
public static Boolean IsRoot(Installation i)
{
return i.ParentId == 0; // root has ParentId 0 by definition
}
public static Int64 CreateInstallation(Installation installation)
{
return Create(installation);
}
public static Boolean UpdateInstallation(Installation installation)
{
return Update(installation);
}
public static Boolean DeleteInstallation(Installation installation)
{
User2Installation.Delete(i => i.InstallationId == installation.Id);
return Delete(installation);
}
}