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.
72 lines
2.8 KiB
72 lines
2.8 KiB
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using IoT.Shared.Application.Domain.Entities;
|
|
using IoT.Shared.Application.Models;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Platform.Areas.IoTCenter.Controllers;
|
|
using System.Linq;
|
|
|
|
namespace IoT.Shared.Areas.UserCenter.Controllers
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("UserCenter/[controller]/[action]")]
|
|
[Area("UserCenter")]
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
public class OrganRoleController : CrudController<OrganRole, EditRoleModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
private readonly IRepository<Organ> _organRepo;
|
|
|
|
public OrganRoleController(IRepository<OrganRole> repo, AjaxController ajax, IRepository<Organ> organRepo) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
this._organRepo = organRepo;
|
|
}
|
|
|
|
public override IQueryable<OrganRole> Include(IQueryable<OrganRole> query)
|
|
{
|
|
return query
|
|
.Include(o => o.Organ)
|
|
.Include(o=>o.RolePermissions).ThenInclude(o=>o.Permission);
|
|
}
|
|
|
|
public override IQueryable<OrganRole> Query(PagedListModel<EditRoleModel> model, IQueryable<OrganRole> query)
|
|
{
|
|
return base.Query(model, query)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
|
|
.WhereIf(model.Query.OrganId.HasValue, o => o.OrganId == model.Query.OrganId.Value)
|
|
.OrderBy(o => o.Name);
|
|
}
|
|
|
|
public override void ToDisplayModel(OrganRole entity, EditRoleModel model)
|
|
{
|
|
var name = this._organRepo.ReadOnlyTable()
|
|
.Where(o => o.Left <= entity.Organ.Left && o.Left > 1)
|
|
.ToList()
|
|
.ToTree()
|
|
.FirstOrDefault(o => o.Id == entity.OrganId)?.GetDisplayName();
|
|
ViewData.Add(model.OrganId, name);
|
|
model.Permissions = entity.RolePermissions.Select(o => o.PermissionId).ToList();
|
|
entity.RolePermissions.ForEach(o => ViewData.Add(o.PermissionId, o.Permission.Name));
|
|
}
|
|
|
|
public override void ToEditModel(OrganRole entity, EditRoleModel model)
|
|
{
|
|
this.ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
|
|
if (entity != null)
|
|
{
|
|
model.Permissions = entity.RolePermissions.Select(o => o.PermissionId).ToList();
|
|
}
|
|
if (model.OrganId.HasValue)
|
|
{
|
|
ViewData.MultiSelectList(o => model.Permissions, () => this._ajax.GetPermission(model.OrganId.Value, model.Permissions).MultiSelectList());
|
|
}
|
|
}
|
|
}
|
|
}
|