123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- using System.Linq;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using FMSAdmin.Data;
- using FMSAdmin.Helpers;
- using FMSAdmin.Entities;
- using FMSAdmin.Services;
- using Microsoft.AspNetCore.Authorization;
- namespace FMSAdmin.Controllers {
- [Authorize]
- [ApiController]
- [ApiVersion("1")]
- [Route("api/[controller]")]
- public class SitemapAuthController : Controller {
- private readonly ILogger<SitemapAuthController> _logger;
- private readonly FMSContext _context;
- private readonly SitemapAuthService _service;
- public SitemapAuthController(
- ILogger<SitemapAuthController> logger,
- FMSContext context,
- SitemapAuthService service
- ) {
- _logger = logger;
- _context = context;
- _service = service;
- }
- /// <summary>
- /// 권한 일괄 수정
- /// </summary>
- /// <param name="siteId"></param>
- /// <param name="userGroupId"></param>
- /// <param name="type"></param>
- /// <param name="list"></param>
- /// <returns></returns>
- [HttpPost("{type}")]
- public IActionResult Edit(int siteId, int userGroupId, SitemapType type, [FromBody]SitemapAuth[] list) {
- _logger.LogInformation(list.Dump());
- if (list == null) {
- return BadRequest("데이터를 입력해주세요");
- }
- foreach (var data in list) {
- if (data.SiteId != siteId) {
- return BadRequest("현장정보가 잘못되었습니다");
- }
- if (data.UserGroupId != userGroupId) {
- return BadRequest("사용자그룹이 잘못되었습니다");
- }
- if (data.SitemapType != type) {
- return BadRequest("메뉴종류가 잘못되었습니다");
- }
- }
- _service.Save(siteId, userGroupId, type, list);
- return Ok(list.Count());
- }
- /// <summary>
- /// 자식 노드 리스트
- /// </summary>
- /// <param name="parentId"></param>
- /// <param name="type"></param>
- /// <returns></returns>
- [HttpGet("childs/{type}/{parentId?}")]
- public IActionResult Childs(int siteId, int userGroupId, SitemapType type, int? parentId) {
- var query = _service.SitemapAll().Where(x => x.Type == type && x.ParentId == parentId);
- // 최대 4뎁스
- var list = query.OrderBy(x => x.Position).Select(c => new {
- key = c.SitemapId,
- title = c.Name,
- action1 = c.Action1,
- action2 = c.Action2,
- action3 = c.Action3,
- action4 = c.Action4,
- action5 = c.Action5,
- auth = c.SitemapAuths.Where(x => x.SiteId == siteId && x.UserGroupId == userGroupId).Select(x => new {
- x.Access,
- x.Update,
- x.Delete,
- x.Business,
- x.Action1,
- x.Action2,
- x.Action3,
- x.Action4,
- x.Action5
- }).FirstOrDefault(),
- children = c.Childs.OrderBy(x => x.Position).Select(c1 => new {
- key = c1.SitemapId,
- title = c1.Name,
- action1 = c1.Action1,
- action2 = c1.Action2,
- action3 = c1.Action3,
- action4 = c1.Action4,
- action5 = c1.Action5,
- auth = c1.SitemapAuths.Where(x => x.SiteId == siteId && x.UserGroupId == userGroupId).Select(x => new {
- x.Access,
- x.Update,
- x.Delete,
- x.Business,
- x.Action1,
- x.Action2,
- x.Action3,
- x.Action4,
- x.Action5
- }).FirstOrDefault(),
- children = c1.Childs.OrderBy(x => x.Position).Select(c2 => new {
- key = c2.SitemapId,
- title = c2.Name,
- action1 = c2.Action1,
- action2 = c2.Action2,
- action3 = c2.Action3,
- action4 = c2.Action4,
- action5 = c2.Action5,
- auth = c2.SitemapAuths.Where(x => x.SiteId == siteId && x.UserGroupId == userGroupId).Select(x => new {
- x.Access,
- x.Update,
- x.Delete,
- x.Business,
- x.Action1,
- x.Action2,
- x.Action3,
- x.Action4,
- x.Action5
- }).FirstOrDefault(),
- children = c2.Childs.OrderBy(x => x.Position).Select(c3 => new {
- key = c3.SitemapId,
- title = c3.Name,
- action1 = c3.Action1,
- action2 = c3.Action2,
- action3 = c3.Action3,
- action4 = c3.Action4,
- action5 = c3.Action5,
- auth = c3.SitemapAuths.Where(x => x.SiteId == siteId && x.UserGroupId == userGroupId).Select(x => new {
- x.Access,
- x.Update,
- x.Delete,
- x.Business,
- x.Action1,
- x.Action2,
- x.Action3,
- x.Action4,
- x.Action5
- }).FirstOrDefault(),
- })
- })
- })
- });
- return Ok(list);
- }
- }
- }
|