58 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using Marco.Pms.DataAccess.Data;
 | 
						|
using Marco.Pms.Model.Entitlements;
 | 
						|
using Marco.Pms.Model.Mapper;
 | 
						|
using Marco.Pms.Model.Master;
 | 
						|
using Marco.Pms.Model.Utilities;
 | 
						|
using Marco.Pms.Model.ViewModels.Master;
 | 
						|
using Microsoft.AspNetCore.Mvc;
 | 
						|
using Microsoft.EntityFrameworkCore;
 | 
						|
 | 
						|
namespace MarcoBMS.Services.Controllers
 | 
						|
{
 | 
						|
    [Route("api/[controller]")]
 | 
						|
    [ApiController]
 | 
						|
    // [Authorize]
 | 
						|
    public class FeatureController : ControllerBase
 | 
						|
    {
 | 
						|
        private readonly ApplicationDbContext _context;
 | 
						|
 | 
						|
 | 
						|
        public FeatureController(ApplicationDbContext context)
 | 
						|
        {
 | 
						|
            _context = context;
 | 
						|
        }
 | 
						|
 | 
						|
        private ICollection<FeaturePermissionVM> GetFeaturePermissionVMs(Feature model)
 | 
						|
        {
 | 
						|
            ICollection<FeaturePermissionVM> features = [];
 | 
						|
            if (model.FeaturePermissions != null)
 | 
						|
            {
 | 
						|
                foreach (FeaturePermission permission in model.FeaturePermissions)
 | 
						|
                {
 | 
						|
                    FeaturePermissionVM item = permission.ToFeaturePermissionVMFromFeaturePermission();
 | 
						|
                    features.Add(item);
 | 
						|
                }
 | 
						|
            }
 | 
						|
            return features.OrderBy(f => f.Name).ToList();
 | 
						|
        }
 | 
						|
 | 
						|
        [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 != null ? c.Module.Name : string.Empty,
 | 
						|
                IsActive = c.IsActive
 | 
						|
            }).OrderBy(f => f.Name).ToList();
 | 
						|
            return Ok(ApiResponse<object>.SuccessResponse(rolesVM, "Success.", 200));
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |