11using BExIS . App . Bootstrap . Attributes ;
22using BExIS . Dlm . Entities . DataStructure ;
3+ using BExIS . Dlm . Entities . Meanings ;
34using BExIS . Dlm . Services . DataStructure ;
5+ using BExIS . Dlm . Services . Meanings ;
6+ using BExIS . Dlm . Services . MetadataStructure ;
7+ using BExIS . Modules . Rpm . UI . Models ;
48using BExIS . Modules . Rpm . UI . Models ;
59using BExIS . Modules . Rpm . UI . Models . Dimensions ;
610using BExIS . Modules . Rpm . UI . Models . Units ;
711using BExIS . UI . Helpers ;
12+ using BExIS . Utils . NH . Querying ;
813using System ;
914using System . Collections . Generic ;
1015using System . Linq ;
11- using BExIS . Modules . Rpm . UI . Models ;
12- using BExIS . Dlm . Entities . Meanings ;
13- using BExIS . Dlm . Services . Meanings ;
14- using BExIS . Utils . NH . Querying ;
1516using System . Web . Mvc ;
16- using BExIS . Dlm . Services . MetadataStructure ;
1717
1818namespace BExIS . Modules . Rpm . UI . Controllers
1919{
@@ -35,7 +35,7 @@ public JsonResult GetUnits()
3535 {
3636 using ( UnitManager unitManager = new UnitManager ( ) )
3737 {
38- return Json ( convertToUnitListItem ( unitManager . Repo . Get ( ) . OrderBy ( u => u . Id ) . ToList ( ) ) , JsonRequestBehavior . AllowGet ) ;
38+ return Json ( convertToUnitListItem ( unitManager . Repo . Query ( ) . OrderBy ( u => u . Id ) . ToList ( ) ) , JsonRequestBehavior . AllowGet ) ;
3939 }
4040 }
4141
@@ -256,12 +256,34 @@ private List<UnitListItem> convertToUnitListItem(List<Unit> units)
256256 using ( var metadataAttributeManager = new MetadataAttributeManager ( ) )
257257 using ( var variableManager = new VariableManager ( ) )
258258 {
259+ Dictionary < long , long > maUsage = new Dictionary < long , long > ( ) ;
260+ Dictionary < long , long > viUsage = new Dictionary < long , long > ( ) ;
261+ Dictionary < long , long > vtUsage = new Dictionary < long , long > ( ) ;
262+
263+ // metadata attributes
264+ var mas = metadataAttributeManager . MetadataAttributeRepo . Query ( ma => ma . Unit != null ) . Select ( x => new {
265+ Id = x . Id ,
266+ UnitId = x . Unit . Id
267+ } ) ;
268+
269+ // variable instance
270+ var vis = variableManager . VariableInstanceRepo . Query ( v => v . Unit != null ) . Select ( x => new {
271+ Id = x . Id ,
272+ UnitId = x . Unit . Id
273+ } ) ;
274+ // variable templates
275+ var vts = variableManager . VariableTemplateRepo . Query ( v => v . Unit != null ) . Select ( x => new {
276+ Id = x . Id ,
277+ UnitId = x . Unit . Id
278+ } ) ;
279+
259280 foreach ( Unit unit in units )
260- {
281+ {
261282 bool inUse = false ;
262- inUse = metadataAttributeManager . MetadataAttributeRepo . Query ( ) . Any ( ma => ma . Unit != null && ma . Unit . Id == unit . Id ) ;
263- if ( ! inUse ) inUse = variableManager . VariableInstanceRepo . Query ( ) . Any ( v => v . Unit != null && v . Unit . Id == unit . Id ) ;
264- if ( ! inUse ) inUse = variableManager . VariableTemplateRepo . Query ( ) . Any ( v => v . Unit != null && v . Unit . Id == unit . Id ) ;
283+
284+ inUse = mas . Any ( ma => ma . UnitId == unit . Id ) ;
285+ if ( ! inUse ) inUse = vis . Any ( v => v . UnitId == unit . Id ) ;
286+ if ( ! inUse ) inUse = vts . Any ( v => v . UnitId == unit . Id ) ;
265287
266288 unitListItems . Add ( convertToUnitListItem ( unit , inUse ) ) ;
267289 }
0 commit comments