@@ -24,6 +24,18 @@ public BuildingUnitDetailProjections(WKBReader wkbReader)
2424 _wkbReader = wkbReader ;
2525
2626 #region Building
27+ When < Envelope < BuildingWasRegistered > > ( async ( context , message , ct ) =>
28+ {
29+ await context
30+ . BuildingUnitBuildings
31+ . AddAsync (
32+ new BuildingUnitBuildingItem
33+ {
34+ BuildingId = message . Message . BuildingId ,
35+ IsRemoved = false
36+ } , ct ) ;
37+ } ) ;
38+
2739 When < Envelope < BuildingWasRemoved > > ( async ( context , message , ct ) =>
2840 {
2941 // possible of ALOT of units, might exceed SQL server IN (...) limitation, thats why we first get id by BuildingId
@@ -43,30 +55,45 @@ public BuildingUnitDetailProjections(WKBReader wkbReader)
4355 SetVersion ( buildingUnitDetailItem , message . Message . Provenance . Timestamp ) ;
4456 }
4557 }
58+
59+ var building = await context . BuildingUnitBuildings . FindAsync ( message . Message . BuildingId , cancellationToken : ct ) ;
60+ building . IsRemoved = true ;
4661 } ) ;
4762
4863 When < Envelope < BuildingWasRetired > > ( async ( context , message , ct ) =>
4964 {
5065 var buildingUnits = await context . BuildingUnitDetails . Where ( unit => unit . BuildingId == message . Message . BuildingId ) . ToListAsync ( ct ) ;
5166 RetireUnitsByBuilding ( buildingUnits , message . Message . BuildingUnitIdsToNotRealize , message . Message . BuildingUnitIdsToRetire , message . Message . Provenance . Timestamp ) ;
67+
68+ var building = await context . BuildingUnitBuildings . FindAsync ( message . Message . BuildingId , cancellationToken : ct ) ;
69+ building . BuildingRetiredStatus = BuildingStatus . Retired ;
5270 } ) ;
5371
5472 When < Envelope < BuildingWasCorrectedToRetired > > ( async ( context , message , ct ) =>
5573 {
5674 var buildingUnits = await context . BuildingUnitDetails . Where ( unit => unit . BuildingId == message . Message . BuildingId ) . ToListAsync ( ct ) ;
5775 RetireUnitsByBuilding ( buildingUnits , message . Message . BuildingUnitIdsToNotRealize , message . Message . BuildingUnitIdsToRetire , message . Message . Provenance . Timestamp ) ;
76+
77+ var building = await context . BuildingUnitBuildings . FindAsync ( message . Message . BuildingId , cancellationToken : ct ) ;
78+ building . BuildingRetiredStatus = BuildingStatus . Retired ;
5879 } ) ;
5980
6081 When < Envelope < BuildingWasNotRealized > > ( async ( context , message , ct ) =>
6182 {
6283 var buildingUnits = await context . BuildingUnitDetails . Where ( unit => unit . BuildingId == message . Message . BuildingId ) . ToListAsync ( ct ) ;
6384 RetireUnitsByBuilding ( buildingUnits , message . Message . BuildingUnitIdsToNotRealize , message . Message . BuildingUnitIdsToRetire , message . Message . Provenance . Timestamp ) ;
85+
86+ var building = await context . BuildingUnitBuildings . FindAsync ( message . Message . BuildingId , cancellationToken : ct ) ;
87+ building . BuildingRetiredStatus = BuildingStatus . NotRealized ;
6488 } ) ;
6589
6690 When < Envelope < BuildingWasCorrectedToNotRealized > > ( async ( context , message , ct ) =>
6791 {
6892 var buildingUnits = await context . BuildingUnitDetails . Where ( unit => unit . BuildingId == message . Message . BuildingId ) . ToListAsync ( ct ) ;
6993 RetireUnitsByBuilding ( buildingUnits , message . Message . BuildingUnitIdsToNotRealize , message . Message . BuildingUnitIdsToRetire , message . Message . Provenance . Timestamp ) ;
94+
95+ var building = await context . BuildingUnitBuildings . FindAsync ( message . Message . BuildingId , cancellationToken : ct ) ;
96+ building . BuildingRetiredStatus = BuildingStatus . NotRealized ;
7097 } ) ;
7198
7299 When < Envelope < BuildingGeometryWasRemoved > > ( async ( context , message , ct ) =>
@@ -88,6 +115,9 @@ public BuildingUnitDetailProjections(WKBReader wkbReader)
88115 buildingUnit . IsBuildingComplete = true ;
89116 SetVersion ( buildingUnit , message . Message . Provenance . Timestamp ) ;
90117 }
118+
119+ var building = await context . BuildingUnitBuildings . FindAsync ( message . Message . BuildingId , cancellationToken : ct ) ;
120+ building . IsComplete = true ;
91121 } ) ;
92122
93123 When < Envelope < BuildingBecameIncomplete > > ( async ( context , message , ct ) =>
@@ -98,17 +128,15 @@ public BuildingUnitDetailProjections(WKBReader wkbReader)
98128 buildingUnit . IsBuildingComplete = false ;
99129 SetVersion ( buildingUnit , message . Message . Provenance . Timestamp ) ;
100130 }
131+
132+ var building = await context . BuildingUnitBuildings . FindAsync ( message . Message . BuildingId , cancellationToken : ct ) ;
133+ building . IsComplete = false ;
101134 } ) ;
102135
103136 When < Envelope < BuildingOsloIdWasAssigned > > ( async ( context , message , ct ) =>
104137 {
105- await context
106- . BuildingUnitBuildingOsloIds
107- . AddAsync ( new BuildingUnitBuildingOsloIdItem
108- {
109- BuildingId = message . Message . BuildingId ,
110- BuildingOsloId = message . Message . OsloId ,
111- } , cancellationToken : ct ) ;
138+ var building = await context . BuildingUnitBuildings . FindAsync ( message . Message . BuildingId , cancellationToken : ct ) ;
139+ building . BuildingOsloId = message . Message . OsloId ;
112140
113141 foreach ( var buildingUnit in context
114142 . BuildingUnitDetails
@@ -384,15 +412,16 @@ private static async Task AddUnit(LegacyContext context,
384412 bool isCommon ,
385413 CancellationToken ct )
386414 {
387- var buildingOsloId = await context
388- . BuildingUnitBuildingOsloIds
415+ var building = await context
416+ . BuildingUnitBuildings
389417 . FindAsync ( buildingId , cancellationToken : ct ) ;
390418
391419 var buildingUnitDetailItem = new BuildingUnitDetailItem
392420 {
393421 BuildingUnitId = buildingUnitId ,
394422 BuildingId = buildingId ,
395- BuildingOsloId = buildingOsloId ? . BuildingOsloId ,
423+ BuildingOsloId = building ? . BuildingOsloId ,
424+ IsBuildingComplete = building ? . IsComplete ?? false ,
396425 Version = version ,
397426 Function = isCommon ? BuildingUnitFunction . Common : BuildingUnitFunction . Unknown ,
398427 } ;
0 commit comments