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

54 lines
1.2 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 Folder? GetFolderById(Int64? id)
{
return Folders
.FirstOrDefault(f => f.Id == id);
}
public static Installation? GetInstallationById(Int64? id)
{
return Installations
.FirstOrDefault(i => i.Id == id);
}
public static User? GetUserById(Int64? id)
{
return Users
.FirstOrDefault(u => u.Id == id);
}
public static User? GetUserByEmail(String userName)
{
return Users
.FirstOrDefault(u => u.Email == userName);
}
public static Session? GetSession(String token)
{
var session = Sessions
.FirstOrDefault(s => s.Token == token);
// cannot use session.Valid in the DB query above.
// It does not exist in the db (IgnoreAttribute)
if (session is null)
return null;
if (!session.Valid)
{
Delete(session);
return null;
}
return session;
}
}