updating installations with new order numbers automatically updates the ordernumber2installation relation table

This commit is contained in:
Kim 2023-03-23 14:58:59 +01:00
parent b07991e75d
commit 55628e2186
5 changed files with 42 additions and 10 deletions

View File

@ -98,15 +98,39 @@ public static class SessionMethods
var user = session?.User; var user = session?.User;
var original = Db.GetInstallationById(installation?.Id); var original = Db.GetInstallationById(installation?.Id);
var originalOrderNumbers = original!.GetOrderNumbers();
if (!Equals(originalOrderNumbers, installation?.OrderNumbers))
{
foreach (var orderNumber in installation!.OrderNumbers)
{
if (originalOrderNumbers.Contains(orderNumber)) continue;
var o2I = new OrderNumber2Installation
{
OrderNumber = orderNumber,
InstallationId = installation.Id
};
Db.Create(o2I);
}
foreach (var orderNumberOld in originalOrderNumbers)
{
if (!installation!.OrderNumbers.Contains(orderNumberOld))
{
Db.OrderNumber2Installation.Delete(i =>
i.InstallationId == installation.Id && i.OrderNumber == orderNumberOld);
}
}
}
return user is not null return user is not null
&& installation is not null && installation is not null
&& original is not null && original is not null
&& user.HasWriteAccess && user.HasWriteAccess
&& user.HasAccessTo(installation) && user.HasAccessTo(installation)
&& installation && installation
.WithParentOf(original) // prevent moving .WithParentOf(original) // prevent moving
.Apply(Db.Update); .Apply(Db.Update);
} }
public static Boolean Delete(this Session? session, Installation? installation) public static Boolean Delete(this Session? session, Installation? installation)

View File

@ -52,4 +52,9 @@ public static partial class Db
{ {
return Connection.Insert(folderAccess) > 0; return Connection.Insert(folderAccess) > 0;
} }
public static Boolean Create(OrderNumber2Installation o2i)
{
return Connection.Insert(o2i) > 0;
}
} }

View File

@ -100,4 +100,5 @@ public static partial class Db
.Select(i => i.RenewS3BucketUrl()) .Select(i => i.RenewS3BucketUrl())
.WhenAll(); .WhenAll();
} }
} }

View File

@ -4,6 +4,7 @@ namespace InnovEnergy.App.Backend.Relations;
public class OrderNumber2Installation : Relation<String, Int64> public class OrderNumber2Installation : Relation<String, Int64>
{ {
[Indexed] public String OrderNumber { get => Left ; init => Left = value;} [Indexed] public String OrderNumber { get => Left ; set => Left = value;}
[Indexed] public Int64 InstallationId { get => Right; init => Right = value;} [Indexed] public Int64 InstallationId { get => Right; set => Right = value;}
} }

View File

@ -34,6 +34,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=resultset/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=resultset/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Salimax/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Salimax/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=signurl/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=signurl/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Smpt/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Trumpf/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Trumpf/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ttyusb/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=ttyusb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=tupled/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=tupled/@EntryIndexedValue">True</s:Boolean>