+ Added functions access

* Change db and added PLC_ID
This commit is contained in:
Lucio Maranta
2018-02-06 17:36:12 +01:00
parent e8623a5cbd
commit 6cc4d8290e
19 changed files with 180 additions and 22 deletions
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using Step.Model.DatabaseModels;
using Step.Model.DTOModels;
using static CMS_CORE_Library.DataStructures;
namespace Step.Database.Controllers
{
@@ -43,7 +44,31 @@ namespace Step.Database.Controllers
CanRead = f.ReadLevelMin < roleLevel,
CanWrite = f.WriteLevelMin < roleLevel
})
.ToList() ;
.ToList();
}
public List<DTORuntimeFunctionAccessModel> GetFunctionsMappedWithPlc(List<FunctionalityModel> functionalityList)
{
return dbCtx
.FunctionsAccess
.ToList() // Find all function access
.Select(f => new DTORuntimeFunctionAccessModel()
{
Id = f.FunctionAccessId,
Name = f.Name,
Area = f.Area,
Enabled = GetIfFunctionalityIsActive(functionalityList, f.PlcId, f.Enabled) // Get new enabled data
})
.ToList();
}
private bool GetIfFunctionalityIsActive(List<FunctionalityModel> functionalityList, int id, bool functionAccessIsEnabled)
{
// If id is not mapped or function is false by database config return
if (id == 0 || !functionAccessIsEnabled)
return functionAccessIsEnabled;
// Return PLC data
return functionalityList[id - 1].isActive;
}
}
}