Skip to content

Commit f9875f7

Browse files
committed
#2312 change model related to units
1 parent 4720c48 commit f9875f7

File tree

9 files changed

+200
-17
lines changed

9 files changed

+200
-17
lines changed

Components/DLM/BExIS.Dlm.Entities/DataStructure/Unit.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public class Unit : BaseEntity
6969
/// <seealso cref=""/>
7070
public virtual ICollection<DataContainer> DataContainers { get; set; }
7171

72+
73+
public virtual ICollection<Variable> Variables { get; set; }
74+
7275
/// <summary>
7376
///
7477
/// </summary>

Components/DLM/BExIS.Dlm.Orm.NH/Mappings/Default/DataStructure/Unit.hbm.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
<one-to-many class="DataContainer" />
5555
</set>
5656

57+
<set name="Variables" inverse="true" cascade="save-update">
58+
<key column="UnitRef" not-null="false" />
59+
<one-to-many class="Variable" />
60+
</set>
61+
5762
<set name="AssociatedDataTypes" table="Units_DataTypes" cascade="save-update" lazy="false">
5863
<key column="UnitRef" />
5964
<many-to-many column="DataTypeRef" class="DataType" />

Components/DLM/BExIS.Dlm.Services/DataStructure/UnitManager.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BExIS.Dlm.Entities.DataStructure;
2+
using BExIS.Security.Entities.Requests;
23
using System;
34
using System.Collections.Generic;
45
using System.Diagnostics.Contracts;
@@ -9,16 +10,16 @@ namespace BExIS.Dlm.Services.DataStructure
910
{
1011
public class UnitManager : IDisposable
1112
{
12-
private IUnitOfWork guow = null;
13+
private IUnitOfWork _guow = null;
1314

1415
public UnitManager() //: base(false, true, true)
1516
{
16-
//// define aggregate paths
17-
////AggregatePaths.Add((Unit u) => u.ConversionsIamTheSource);
18-
guow = this.GetIsolatedUnitOfWork();
19-
this.Repo = guow.GetReadOnlyRepository<Unit>();
17+
_guow = this.GetIsolatedUnitOfWork();
18+
UnitRepository = _guow.GetReadOnlyRepository<Unit>();
19+
DimensionRepository = _guow.GetReadOnlyRepository<Dimension>();
20+
this.Repo = _guow.GetReadOnlyRepository<Unit>();
2021
//this.ConversionMethodRepo = uow.GetReadOnlyRepository<ConversionMethod>();
21-
this.DimensionRepo = guow.GetReadOnlyRepository<Dimension>();
22+
this.DimensionRepo = _guow.GetReadOnlyRepository<Dimension>();
2223
}
2324

2425
private bool isDisposed = false;
@@ -39,15 +40,19 @@ protected virtual void Dispose(bool disposing)
3940
{
4041
if (disposing)
4142
{
42-
if (guow != null)
43-
guow.Dispose();
43+
if (_guow != null)
44+
_guow.Dispose();
4445
isDisposed = true;
4546
}
4647
}
4748
}
4849

4950
#region Data Readers
5051

52+
public IReadOnlyRepository<Unit> UnitRepository { get; }
53+
public IReadOnlyRepository<Dimension> DimensionRepository { get; }
54+
public IQueryable<Unit> Units => UnitRepository.Query();
55+
5156
// provide read only repos for the whole aggregate area
5257
public IReadOnlyRepository<Unit> Repo { get; private set; }
5358

Console/BExIS.Web.Shell/Areas/RPM/BExIS.Modules.Rpm.UI/BExIS.Modules.Rpm.UI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
<Compile Include="Models\DataStructure\DataStructureCreationModel.cs" />
143143
<Compile Include="Models\DataTypeModels.cs" />
144144
<Compile Include="Models\DimensionModels.cs" />
145+
<Compile Include="Models\LinkModels.cs" />
145146
<Compile Include="Models\Models.cs" />
146147
<Compile Include="Models\MeaningModels.cs" />
147148
<Compile Include="Models\UnitModels.cs" />

Console/BExIS.Web.Shell/Areas/RPM/BExIS.Modules.Rpm.UI/Controllers/UnitController.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
using BExIS.App.Bootstrap.Attributes;
22
using BExIS.Dlm.Entities.DataStructure;
3+
using BExIS.Dlm.Entities.Meanings;
34
using BExIS.Dlm.Services.DataStructure;
5+
using BExIS.Dlm.Services.Meanings;
6+
using BExIS.Dlm.Services.MetadataStructure;
7+
using BExIS.Modules.Rpm.UI.Models;
48
using BExIS.Modules.Rpm.UI.Models;
59
using BExIS.Modules.Rpm.UI.Models.Dimensions;
610
using BExIS.Modules.Rpm.UI.Models.Units;
11+
using BExIS.Security.Entities.Subjects;
12+
using BExIS.Security.Services.Subjects;
713
using BExIS.UI.Helpers;
14+
using BExIS.Utils.NH.Querying;
815
using System;
916
using System.Collections.Generic;
1017
using 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;
1518
using System.Web.Mvc;
16-
using BExIS.Dlm.Services.MetadataStructure;
19+
using Telerik.Web.Mvc;
1720

1821
namespace BExIS.Modules.Rpm.UI.Controllers
1922
{
@@ -33,9 +36,16 @@ public ActionResult Index()
3336
[HttpGet]
3437
public JsonResult GetUnits()
3538
{
36-
using (UnitManager unitManager = new UnitManager())
39+
using(var unitManager = new UnitManager())
3740
{
38-
return Json(convertToUnitListItem(unitManager.Repo.Get().OrderBy(u => u.Id).ToList()), JsonRequestBehavior.AllowGet);
41+
var units = new List<ReadUnitModel>();
42+
43+
foreach (var unit in unitManager.Units)
44+
{
45+
units.Add(ReadUnitModel.Convert(unit));
46+
}
47+
48+
return Json(units, JsonRequestBehavior.AllowGet);
3949
}
4050
}
4151

Console/BExIS.Web.Shell/Areas/RPM/BExIS.Modules.Rpm.UI/Models/DataTypeModels.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace BExIS.Modules.Rpm.UI.Models.DataTypes
1+
using BExIS.Dlm.Entities.DataStructure;
2+
using BExIS.Modules.Rpm.UI.Models.Dimensions;
3+
4+
namespace BExIS.Modules.Rpm.UI.Models.DataTypes
25
{
36
public class DataTypeListItem
47
{
@@ -32,5 +35,37 @@ public DataTypeListItem()
3235
SystemType = string.Empty;
3336
InUse = false;
3437
}
38+
39+
public static DataTypeListItem Convert(DataType dataType)
40+
{
41+
return new DataTypeListItem()
42+
{
43+
Id = dataType.Id,
44+
Name = dataType.Name,
45+
Description = dataType.Description,
46+
SystemType = dataType.SystemType,
47+
InUse = dataType.DataContainers.Count > 0
48+
};
49+
}
50+
}
51+
public class ReadDataTypeModel
52+
{
53+
public long Id { get; set; }
54+
public string Name { get; set; }
55+
public string Description { get; set; }
56+
public string SystemType { get; set; }
57+
public bool IsInUse { get; set; }
58+
59+
public static ReadDataTypeModel Convert(DataType dataType)
60+
{
61+
return new ReadDataTypeModel()
62+
{
63+
Id = dataType.Id,
64+
Name = dataType.Name,
65+
Description = dataType.Description,
66+
SystemType = dataType.SystemType,
67+
IsInUse = dataType.DataContainers.Count > 0
68+
};
69+
}
3570
}
3671
}

Console/BExIS.Web.Shell/Areas/RPM/BExIS.Modules.Rpm.UI/Models/DimensionModels.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace BExIS.Modules.Rpm.UI.Models.Dimensions
1+
using BExIS.Dlm.Entities.DataStructure;
2+
using BExIS.Security.Entities.Subjects;
3+
4+
namespace BExIS.Modules.Rpm.UI.Models.Dimensions
25
{
36
public class DimensionListItem
47
{
@@ -32,5 +35,38 @@ public DimensionListItem()
3235
Specification = string.Empty;
3336
InUse = false;
3437
}
38+
39+
public static DimensionListItem Convert(Dimension dimension)
40+
{
41+
return new DimensionListItem()
42+
{
43+
Id = dimension.Id,
44+
Name = dimension.Name,
45+
Description = dimension.Description,
46+
Specification = dimension.Specification,
47+
InUse = dimension.Units.Count > 0
48+
};
49+
}
50+
}
51+
52+
public class ReadDimensionModel
53+
{
54+
public long Id { get; set; }
55+
public string Name { get; set; }
56+
public string Description { get; set; }
57+
public string Specification { get; set; }
58+
public bool IsInUse { get; set; }
59+
60+
public static ReadDimensionModel Convert(Dimension dimension)
61+
{
62+
return new ReadDimensionModel()
63+
{
64+
Id = dimension.Id,
65+
Name = dimension.Name,
66+
Description = dimension.Description,
67+
Specification = dimension.Specification,
68+
IsInUse = dimension.Units.Count > 0
69+
};
70+
}
3571
}
3672
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using BExIS.Dlm.Entities.Meanings;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Web;
6+
7+
namespace BExIS.Modules.Rpm.UI.Models
8+
{
9+
public class ReadLinkModel
10+
{
11+
public long Id { get; set; }
12+
public string URI { get; set; }
13+
public string Name { get; set; }
14+
15+
public static ReadLinkModel Convert(ExternalLink link)
16+
{
17+
return new ReadLinkModel()
18+
{
19+
Id = link.Id,
20+
Name = link.Name,
21+
URI = link.URI
22+
};
23+
}
24+
}
25+
}

Console/BExIS.Web.Shell/Areas/RPM/BExIS.Modules.Rpm.UI/Models/UnitModels.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
using BExIS.Modules.Rpm.UI.Models.Dimensions;
66
using BExIS.Modules.Rpm.UI.Models.Dimensions;
77
using System.Collections.Generic;
8+
using BExIS.Dlm.Entities.DataStructure;
9+
using System.Linq;
10+
using BExIS.Modules.Rpm.UI.Models.DataTypes;
811

912

1013
namespace BExIS.Modules.Rpm.UI.Models.Units
@@ -61,6 +64,27 @@ public UnitListItem()
6164
InUse = false;
6265
Link = new LinkItem();
6366
}
67+
68+
public static UnitListItem Convert(Unit unit)
69+
{
70+
return new UnitListItem()
71+
{
72+
Id = unit.Id,
73+
Name = unit.Name,
74+
Description = unit.Description,
75+
Abbreviation = unit.Abbreviation,
76+
MeasurementSystem = unit.MeasurementSystem != null ? unit.MeasurementSystem.ToString() : string.Empty,
77+
Dimension = DimensionListItem.Convert(unit.Dimension),
78+
InUse = unit.DataContainers.Count > 0 || unit.Variables.Count > 0,
79+
Link = unit.ExternalLink != null ? new LinkItem()
80+
{
81+
Id = unit.ExternalLink.Id,
82+
Name = unit.ExternalLink.Name,
83+
URI = unit.ExternalLink.URI
84+
} : new LinkItem(),
85+
Datatypes = unit.AssociatedDataTypes.Select(d => DataTypeListItem.Convert(d)).ToList()
86+
};
87+
}
6488
}
6589

6690
public class LinkItem
@@ -106,5 +130,44 @@ public DataTypeListItem()
106130
Description = string.Empty;
107131
SystemType = string.Empty;
108132
}
133+
134+
public static DataTypeListItem Convert(DataType dataType)
135+
{
136+
return new DataTypeListItem()
137+
{
138+
Id = dataType.Id,
139+
Name = dataType.Name,
140+
Description = dataType.Description,
141+
SystemType = dataType.SystemType.ToString()
142+
};
143+
}
144+
}
145+
146+
public class ReadUnitModel
147+
{
148+
public long Id { get; set; }
149+
public string Name { get; set; }
150+
public string Description { get; set; }
151+
public string Abbreviation { get; set; }
152+
public ReadDimensionModel Dimension { get; set; }
153+
public List<ReadDataTypeModel> Datatypes { get; set; }
154+
public MeasurementSystem MeasurementSystem { get; set; }
155+
public bool IsInUse { get; set; }
156+
public ReadLinkModel Link { get; set; }
157+
public static ReadUnitModel Convert(Unit unit)
158+
{
159+
return new ReadUnitModel()
160+
{
161+
Id = unit.Id,
162+
Name = unit.Name,
163+
Description = unit.Description,
164+
Abbreviation = unit.Abbreviation,
165+
MeasurementSystem = unit.MeasurementSystem,
166+
Dimension = ReadDimensionModel.Convert(unit.Dimension),
167+
IsInUse = unit.DataContainers.Count > 0 || unit.Variables.Count > 0,
168+
Link = unit.ExternalLink != null ? ReadLinkModel.Convert(unit.ExternalLink) : new ReadLinkModel(),
169+
Datatypes = unit.AssociatedDataTypes.Select(d => ReadDataTypeModel.Convert(d)).ToList()
170+
};
171+
}
109172
}
110173
}

0 commit comments

Comments
 (0)