using InnovEnergy.App.Backend.Model; using SQLite; namespace InnovEnergy.App.Backend.Database; public static partial class Db { private static TableQuery Installations => _Db.Table(); public static Int32 NbInstallations => Installations.Count(); public static Installation? GetInstallationById(Int64 id) => Installations .FirstOrDefault(u => u.Id == id); private static IEnumerable Ancestors(Installation installation) { var parentFolder = GetParent(installation); return parentFolder is null ? Enumerable.Empty() : 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); } }