2023-03-15 13:38:06 +00:00
|
|
|
using InnovEnergy.App.Backend.Relations;
|
2023-02-16 12:57:06 +00:00
|
|
|
|
2023-03-08 12:20:33 +00:00
|
|
|
namespace InnovEnergy.App.Backend.Database;
|
2023-02-16 12:57:06 +00:00
|
|
|
|
2023-03-13 10:36:50 +00:00
|
|
|
public static partial class Db
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
2023-03-13 10:36:50 +00:00
|
|
|
public static void CreateFakeRelations()
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
2023-03-13 10:48:04 +00:00
|
|
|
Connection.RunInTransaction(() =>
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
|
|
|
CreateFakeUserTree();
|
|
|
|
CreateFakeFolderTree();
|
|
|
|
LinkFakeInstallationsToFolders();
|
|
|
|
GiveFakeUsersAccessToFolders();
|
|
|
|
GiveFakeUsersAccessToInstallations();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-13 10:36:50 +00:00
|
|
|
private static void CreateFakeUserTree()
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
2023-03-15 13:38:06 +00:00
|
|
|
foreach (var userId in Enumerable.Range(1, Users.Count()))
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
|
|
|
var user = GetUserById(userId);
|
|
|
|
if (user is null)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
user.ParentId = userId > 1
|
|
|
|
? Random.Shared.Next(userId - 1) + 1
|
|
|
|
: 0; // root has parentId 0
|
|
|
|
|
|
|
|
Update(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-13 10:36:50 +00:00
|
|
|
private static void CreateFakeFolderTree()
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
2023-03-15 13:38:06 +00:00
|
|
|
foreach (var folderId in Enumerable.Range(1, Folders.Count()))
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
|
|
|
var folder = GetFolderById(folderId);
|
|
|
|
if (folder is null)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
folder.ParentId = folderId > 1
|
|
|
|
? Random.Shared.Next(folderId - 1) + 1
|
|
|
|
: 0; // root has parentId 0
|
|
|
|
|
|
|
|
Update(folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-13 10:36:50 +00:00
|
|
|
private static void LinkFakeInstallationsToFolders()
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
2023-03-15 13:38:06 +00:00
|
|
|
var nFolders = Folders.Count();
|
2023-02-16 12:57:06 +00:00
|
|
|
|
|
|
|
foreach (var installation in Installations)
|
|
|
|
{
|
|
|
|
installation.ParentId = Random.Shared.Next(nFolders) + 1;
|
|
|
|
Update(installation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-13 10:36:50 +00:00
|
|
|
private static void GiveFakeUsersAccessToFolders()
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
2023-03-16 10:16:23 +00:00
|
|
|
foreach (var uf in FolderAccess) // remove existing relations
|
2023-03-13 10:48:04 +00:00
|
|
|
Connection.Delete(uf);
|
2023-02-16 12:57:06 +00:00
|
|
|
|
2023-03-15 13:38:06 +00:00
|
|
|
var nFolders = Folders.Count();
|
|
|
|
var nUsers = Users.Count();
|
2023-02-16 12:57:06 +00:00
|
|
|
|
|
|
|
foreach (var user in Users)
|
2023-02-23 10:26:55 +00:00
|
|
|
while (Random.Shared.Next((Int32)(nUsers - user.Id + 1)) != 0)
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
2023-03-16 08:25:36 +00:00
|
|
|
var relation = new FolderAccess
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
|
|
|
UserId = user.Id,
|
|
|
|
FolderId = Random.Shared.Next(nFolders) + 1
|
|
|
|
};
|
2023-03-13 10:48:04 +00:00
|
|
|
Connection.Insert(relation);
|
2023-02-16 12:57:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-13 10:36:50 +00:00
|
|
|
private static void GiveFakeUsersAccessToInstallations()
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
2023-03-16 10:16:23 +00:00
|
|
|
foreach (var ui in InstallationAccess) // remove existing relations
|
2023-03-13 10:48:04 +00:00
|
|
|
Connection.Delete(ui);
|
2023-02-16 12:57:06 +00:00
|
|
|
|
2023-03-15 13:38:06 +00:00
|
|
|
var nbInstallations = Installations.Count();
|
2023-02-16 12:57:06 +00:00
|
|
|
|
|
|
|
foreach (var user in Users)
|
|
|
|
while (Random.Shared.Next(5) != 0)
|
|
|
|
{
|
2023-03-16 08:25:36 +00:00
|
|
|
var relation = new InstallationAccess
|
2023-02-16 12:57:06 +00:00
|
|
|
{
|
|
|
|
UserId = user.Id,
|
|
|
|
InstallationId = Random.Shared.Next(nbInstallations) + 1
|
|
|
|
};
|
2023-03-13 10:48:04 +00:00
|
|
|
Connection.Insert(relation);
|
2023-02-16 12:57:06 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-06 08:36:42 +00:00
|
|
|
//TODO fake OrderNumbers
|
2023-02-16 12:57:06 +00:00
|
|
|
}
|