mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-04-05 17:38:01 +08:00
111 lines
2.7 KiB
C#
111 lines
2.7 KiB
C#
using System;
|
||
using Infrastructure;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using OpenAuth.App;
|
||
using OpenAuth.Repository.Domain;
|
||
|
||
namespace OpenAuth.WebApi.Controllers
|
||
{
|
||
/// <summary>
|
||
/// 机构操作
|
||
/// </summary>
|
||
[Route("api/[controller]/[action]")]
|
||
[ApiController]
|
||
[ApiExplorerSettings(GroupName = "组织机构_Orgs")]
|
||
public class OrgsController : ControllerBase
|
||
{
|
||
private readonly OrgManagerApp _app;
|
||
|
||
/// <summary>
|
||
/// 获取机构详情
|
||
/// </summary>
|
||
[HttpGet]
|
||
public Response<SysOrg> Get(string id)
|
||
{
|
||
var result = new Response<SysOrg>();
|
||
try
|
||
{
|
||
result.Result = _app.Get(id);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result.Code = 500;
|
||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新增机构
|
||
/// <para>如果ID为空,会自动创建ID;会自动为当前登录用户分配添加的机构</para>
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public Response<SysOrg> Add(SysOrg obj)
|
||
{
|
||
var result = new Response<SysOrg>();
|
||
try
|
||
{
|
||
_app.Add(obj);
|
||
result.Result = obj;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result.Code = 500;
|
||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
//添加或修改
|
||
[HttpPost]
|
||
public Response Update(SysOrg obj)
|
||
{
|
||
var result = new Response();
|
||
try
|
||
{
|
||
_app.Update(obj);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result.Code = 500;
|
||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 删除选中的部门及所有的子部门
|
||
/// </summary>
|
||
/// <param name="ids"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public Response Delete([FromBody]string[] ids)
|
||
{
|
||
var result = new Response();
|
||
try
|
||
{
|
||
_app.DelOrgCascade(ids);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result.Code = 500;
|
||
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
public OrgsController(OrgManagerApp app)
|
||
{
|
||
_app = app;
|
||
}
|
||
}
|
||
} |