Added session first implementation:
+ Added session in the database and added session controller + Added session in authorize attribute/Login + Added Logout function * Refactor database models
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels;
|
||||
|
||||
namespace Step.Database.Controllers
|
||||
{
|
||||
public class FunctionsAccessController : IDisposable
|
||||
{
|
||||
private DatabaseContext dbCtx;
|
||||
|
||||
public FunctionsAccessController()
|
||||
{
|
||||
// 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() ;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user