using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using ConfigurationApi.IRepositories;
using MadRunFabric.Common;
using MadRunFabric.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace ConfigurationApi.Controllers
{
///
/// 岗位系统
///
[Authorize]
[ApiVersion("6.0")]
[Produces("application/json")]
[Route("api/[controller]")]
public class PostSystemController : BaseController
{
private readonly ILogger _logger;
private readonly ISys_Post_SystemRepository _sys_post_systemrepository;
public PostSystemController(ILogger logger, ISys_Post_SystemRepository sys_post_systemrepository)
{
_logger = logger;
_sys_post_systemrepository = sys_post_systemrepository;
}
///
/// 保存当前选中的系统
///
///
///
///
[HttpPost("savepostsystem")]
public async Task SavePostSystemAsync(string[] ids, string postid)
{
if (ids == null)
return Error("参数错误");
var list_model = new List();
await _sys_post_systemrepository.Remove(x => x.postid == postid);
foreach (var funcId in ids)
{
var model = new Sys_Post_System();
model.postid = postid;
model.systemid = funcId;
model.createby= User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
model.isdelete = 0;
list_model.Add(model);
}
if (await _sys_post_systemrepository.AddRange(list_model))
{
return Success("权限设置成功!");
}
else
{
return Error("权限设置失败!");
}
}
///
/// 获取岗位系统树形结构
///
///
///
[HttpGet("getpostsystem")]
public IActionResult GetPostSystemAsync(string postid)
{
var result = _sys_post_systemrepository.GetPostSystemAsync(postid);
return Success("成功", result);
}
}
}