5b40cf6fb0
* Added language support api * Added canRead canWrite to functions Access api
50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Step.Model.DatabaseModels;
|
|
using Step.Model.DTOModels;
|
|
|
|
namespace Step.Database.Controllers
|
|
{
|
|
public class FunctionAccessController : IDisposable
|
|
{
|
|
private DatabaseContext dbCtx;
|
|
|
|
public FunctionAccessController()
|
|
{
|
|
// Initialize database context
|
|
dbCtx = new DatabaseContext();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database context
|
|
dbCtx.Dispose();
|
|
}
|
|
|
|
public FunctionAccessModel FindEnabledFunctionByName(string functionName)
|
|
{
|
|
return dbCtx
|
|
.FunctionsAccess
|
|
.Where(x => x.Name == functionName && x.Enabled == true) // Find by name and enabled functions
|
|
.FirstOrDefault();
|
|
}
|
|
|
|
public List<DTOFunctionAccessModel> GetFunctionAccess(int roleLevel)
|
|
{
|
|
return dbCtx
|
|
.FunctionsAccess
|
|
.Select(f => new DTOFunctionAccessModel() // Convert from database model to data transfer model
|
|
{
|
|
Id = f.FunctionAccessId,
|
|
Name = f.Name,
|
|
Area = f.Area,
|
|
Enabled = f.Enabled,
|
|
CanRead = f.ReadLevelMin < roleLevel,
|
|
CanWrite = f.WriteLevelMin < roleLevel
|
|
})
|
|
.ToList() ;
|
|
}
|
|
}
|
|
}
|