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.
47 lines
1.7 KiB
47 lines
1.7 KiB
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using Application.Domain.Entities;
|
|
using IoT.Shared.Application.Models;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Platform.Areas.IoTCenter.Controllers;
|
|
using System.Linq;
|
|
|
|
namespace IoT.Shared.Areas.Admin.Controllers
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("Admin/[controller]/[action]")]
|
|
[Area("Admin")]
|
|
[ControllerScope(ControllerScopeType.Organ)]
|
|
public class OrganRoleController : RoleController
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
public OrganRoleController(IRepository<Role> repo, AjaxController ajax, IRepository<Organ> organRepo) : base(repo, ajax, organRepo)
|
|
{
|
|
this._ajax = ajax;
|
|
}
|
|
|
|
public override IQueryable<Role> Query(PagedListModel<EditRoleModel> model, IQueryable<Role> query)
|
|
{
|
|
var organId = User.GetOrganId();
|
|
return base.Query(model, query)
|
|
.WhereIf(organId.HasValue, o => o.OrganId == organId.Value);
|
|
}
|
|
public override void ToEditModel(Role 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.Permissions, ControllerScopeType.Organ).MultiSelectList());
|
|
}
|
|
}
|
|
}
|
|
}
|