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.7 KiB
72 lines
2.7 KiB
using Application.Domain.Entities;
|
|
using Application.Models;
|
|
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace IoT.Shared.Areas.Admin.Controllers
|
|
{
|
|
[Authorize]
|
|
[Area(nameof(Admin))]
|
|
public class PermissionController : CrudController<Permission, PagedListModel<EditPermissionModel>, EditPermissionModel, EditPermissionModel>
|
|
{
|
|
private readonly IRepository<PermissionCategory> _permissionCategoryRepo;
|
|
|
|
public PermissionController(IRepository<Permission> repo, IRepository<PermissionCategory> ajax) : base(repo)
|
|
{
|
|
this._permissionCategoryRepo = ajax;
|
|
}
|
|
|
|
public override IQueryable<Permission> Include(IQueryable<Permission> query)
|
|
{
|
|
return query.Include(o => o.Category).ThenInclude(o => o.Parent);
|
|
}
|
|
|
|
public override IQueryable<Permission> Query(PagedListModel<EditPermissionModel> model, IQueryable<Permission> query)
|
|
{
|
|
return query.OrderBy(o => o.CategoryId).ThenBy(o => o.Name);
|
|
}
|
|
|
|
public override void ToEditModel(Permission entity, EditPermissionModel model)
|
|
{
|
|
this.ViewData.SelectList(o => model.CategoryId, () => this.GetPermissionCategorySelectList(model.CategoryId), model.CategoryId.HasValue);
|
|
}
|
|
|
|
public override void ToDisplayModel(Permission entity, EditPermissionModel model)
|
|
{
|
|
this.ViewData.Add(entity.CategoryId, entity.Category.Name);
|
|
}
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
public SelectList GetPermissionCategorySelectList(Guid? selected)
|
|
{
|
|
var list = this._permissionCategoryRepo.ReadOnlyTable()
|
|
.Select(o => new { o.Id, Name = $"{o.Name}({o.Number})" })
|
|
.ToList();
|
|
return new SelectList(list, "Id", "Name", selected);
|
|
}
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
public MultiSelectList GetPermissionMultiSelectList(IEnumerable<Guid> selectedValues)
|
|
{
|
|
if (selectedValues == null)
|
|
{
|
|
selectedValues = new List<Guid>();
|
|
}
|
|
var list = this.Repo.ReadOnlyTable()
|
|
.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");
|
|
}
|
|
}
|
|
} |