You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.9 KiB
56 lines
1.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Application.Domain.Entities;
|
|
using Application.Models;
|
|
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Web.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace IoTCenter.Areas.Admin.Controllers
|
|
{
|
|
[Authorize]
|
|
[Area(nameof(Admin))]
|
|
public class PermissionController : CrudController<Permission, PagedListModel<EditPermissionModel>, EditPermissionModel, EditPermissionModel>
|
|
{
|
|
private readonly IRepository<Permission> _permissionRepo;
|
|
|
|
public PermissionController(IRepository<Permission> repo) : base(repo)
|
|
{
|
|
this._permissionRepo = repo;
|
|
}
|
|
|
|
public override IQueryable<Permission> Include(IQueryable<Permission> query)
|
|
{
|
|
return query.Include(o => o.Category).ThenInclude(o => o.Parent);
|
|
}
|
|
|
|
public override void ToDisplayModel(Permission entity, EditPermissionModel model)
|
|
{
|
|
model.CategoryName = entity.Category.GetFullName();
|
|
}
|
|
|
|
public override void ToEditModel(Permission entity, EditPermissionModel model)
|
|
{
|
|
model.CategoryName = entity.Category.GetFullName();
|
|
}
|
|
|
|
public MultiSelectList GetPermissionMultiSelectList(IEnumerable<Guid> selectedValues)
|
|
{
|
|
if (selectedValues == null)
|
|
{
|
|
selectedValues = new List<Guid>();
|
|
}
|
|
var list = this._permissionRepo.Table()
|
|
.Include(o => o.Category)
|
|
.OrderBy(o => o.CategoryId).ThenBy(o => o.Name)
|
|
.Select(o => new { o.Id, o.Name, Group = o.Category.Name })
|
|
.ToList();
|
|
return new MultiSelectList(list, "Id", "Name", selectedValues, "Group");
|
|
}
|
|
}
|
|
} |