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.
78 lines
2.5 KiB
78 lines
2.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Application.Domain.Entities;
|
|
using Infrastructure.Data;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace UserCenter.Areas.Admin.Controllers
|
|
{
|
|
[Area("Admin")]
|
|
public class AjaxController
|
|
{
|
|
private readonly ILogger<AjaxController> _logger;
|
|
private readonly IRepository<Role> _roleRepo;
|
|
private readonly IRepository<Permission> _permissionRepo;
|
|
private readonly IRepository<PermissionCategory> _permissionCategoryRepo;
|
|
|
|
public AjaxController(ILogger<AjaxController> logger,
|
|
IRepository<Role> roleRepo,
|
|
IRepository<Permission> permissionRepo,
|
|
IRepository<PermissionCategory> permissionCategoryRepo)
|
|
{
|
|
this._logger = logger;
|
|
this._roleRepo = roleRepo;
|
|
this._permissionRepo = permissionRepo;
|
|
this._permissionCategoryRepo = permissionCategoryRepo;
|
|
}
|
|
|
|
#region Role
|
|
|
|
public MultiSelectList GetRoleMultiSelectList(IEnumerable<Guid> selected)
|
|
{
|
|
if (selected == null)
|
|
{
|
|
selected = new List<Guid>();
|
|
}
|
|
var list = this._roleRepo.ReadOnlyTable()
|
|
.Select(o => new { o.Id, o.Name })
|
|
.ToList();
|
|
return new MultiSelectList(list, "Id", "Name", selected);
|
|
}
|
|
|
|
#endregion Role
|
|
|
|
#region Permission
|
|
|
|
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");
|
|
}
|
|
|
|
#endregion Permission
|
|
|
|
#region PermissionCategory
|
|
|
|
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);
|
|
}
|
|
|
|
#endregion PermissionCategory
|
|
}
|
|
} |