57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using Marco.Pms.DataAccess.Data;
|
|
using Marco.Pms.Model.Entitlements;
|
|
using Marco.Pms.Model.Mapper;
|
|
using Marco.Pms.Model.ViewModels;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace MarcoBMS.Services.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
// [Authorize]
|
|
public class FeatureController : ControllerBase
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
private readonly UserManager<IdentityUser> _userManager;
|
|
|
|
public FeatureController(UserManager<IdentityUser> userManager, ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
_userManager = userManager;
|
|
}
|
|
|
|
private ICollection<FeaturePermissionVM> GetFeaturePermissionVMs(Feature model)
|
|
{
|
|
ICollection<FeaturePermissionVM> features = [];
|
|
foreach (FeaturePermission permission in model.FeaturePermissions)
|
|
{
|
|
FeaturePermissionVM item = permission.ToFeaturePermissionVMFromFeaturePermission();
|
|
features.Add(item);
|
|
}
|
|
|
|
return features;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetAllFeatures()
|
|
{
|
|
var roles = await _context.Features.Include("FeaturePermissions").Include("Module").ToListAsync();
|
|
|
|
var rolesVM = roles.Select(c => new FeatureVM()
|
|
{
|
|
Id = c.Id,
|
|
Name = c.Name,
|
|
Description = c.Description,
|
|
FeaturePermissions = GetFeaturePermissionVMs(c),
|
|
ModuleId = c.ModuleId,
|
|
ModuleName = c.Module.Name,
|
|
IsActive = c.IsActive
|
|
});
|
|
return Ok(rolesVM);
|
|
}
|
|
}
|
|
}
|