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

59 lines
1.6 KiB
C#
Raw Normal View History

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
{
//In this file, we provide all the methods that can be used in order to retrieve information from the database (read)
public static Folder? GetFolderById(Int64? id)
2023-03-15 13:38:06 +00:00
{
return Folders
.FirstOrDefault(f => f.Id == id);
}
public static Installation? GetInstallationById(Int64? id)
2023-03-15 13:38:06 +00:00
{
return Installations
.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);
}
public static User? GetUserById(Int64? id)
2023-03-15 13:38:06 +00:00
{
return Users
.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)
{
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)
{
//This method is called in almost every controller function.
//After logging in, the frontend receives a session object which contains a token. For all the future REST API calls, this token is used for session authentication.
2023-03-15 13:38:06 +00:00
var session = Sessions
.FirstOrDefault(s => s.Token == token);
if (session is null)
{
2023-03-15 13:38:06 +00:00
return null;
}
2023-03-15 13:38:06 +00:00
if (!session.Valid)
{
Delete(session);
return null;
}
return session;
}
}