2023-03-15 13:38:06 +00:00
|
|
|
using InnovEnergy.App.Backend.DataTypes;
|
|
|
|
using InnovEnergy.App.Backend.Relations;
|
|
|
|
|
|
|
|
|
|
|
|
namespace InnovEnergy.App.Backend.Database;
|
|
|
|
|
|
|
|
|
|
|
|
public static partial class Db
|
|
|
|
{
|
2023-03-21 10:45:50 +00:00
|
|
|
public static Folder? GetFolderById(Int64? id)
|
2023-03-15 13:38:06 +00:00
|
|
|
{
|
|
|
|
return Folders
|
|
|
|
.FirstOrDefault(f => f.Id == id);
|
|
|
|
}
|
|
|
|
|
2023-03-21 10:45:50 +00:00
|
|
|
public static Installation? GetInstallationById(Int64? id)
|
2023-03-15 13:38:06 +00:00
|
|
|
{
|
|
|
|
return Installations
|
2023-03-30 07:27:18 +00:00
|
|
|
.FirstOrDefault(i => i.Id == id);
|
2023-03-15 13:38:06 +00:00
|
|
|
}
|
|
|
|
|
2024-07-19 10:36:27 +00:00
|
|
|
public static UserAction? GetActionById(Int64? id)
|
|
|
|
{
|
|
|
|
return UserActions
|
|
|
|
.FirstOrDefault(i => i.Id == id);
|
|
|
|
}
|
|
|
|
|
2023-03-16 12:33:51 +00:00
|
|
|
public static User? GetUserById(Int64? id)
|
2023-03-15 13:38:06 +00:00
|
|
|
{
|
|
|
|
return Users
|
2023-03-30 07:27:18 +00:00
|
|
|
.FirstOrDefault(u => u.Id == id);
|
2023-03-15 13:38:06 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 12:09:38 +00:00
|
|
|
public static User? GetUserByEmail(String email)
|
2023-03-23 11:47:25 +00:00
|
|
|
{
|
|
|
|
return Users
|
2023-10-26 12:09:38 +00:00
|
|
|
.FirstOrDefault(u => u.Email == email);
|
2023-03-15 13:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|