1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System.Collections.Generic;
- using System.IO;
- using System.Threading.Tasks;
- using GxPress.Entity;
- using GxPress.Repository.Interface;
- using GxPress.Result.Department;
- using GxPress.Service.Interface.Department;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- namespace GxPress.Api.AdminControllers
- {
- /// <summary>
- /// 部门
- /// </summary>
- [Route("api/admin/department")]
- [ApiController]
- [Authorize]
- public class AdminDepartmentController : ControllerBase
- {
- private readonly IDepartmentRepository _departmentRepository;
- private readonly IDepartmentService _departmentService;
- public AdminDepartmentController(IDepartmentRepository departmentRepository,IDepartmentService departmentService)
- {
- _departmentRepository = departmentRepository;
- _departmentService = departmentService;
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost]
- public async Task<Department> Add([FromBody]Department request)
- {
- return await _departmentRepository.AddAsync(request);
- }
- /// <summary>
- /// 详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("{id}")]
- public async Task<Department> GetDetail(int id)
- {
- return await _departmentRepository.GetAsync(id);
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpDelete("{id}")]
- public async Task<bool> Delete(int id)
- {
- return await _departmentService.DeleteAsync(id);
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="id"></param>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPut("{id}")]
- public async Task<bool> Update(int id, [FromBody] Department request)
- {
- return await _departmentRepository.UpdateAsync(id, request);
- }
- /// <summary>
- /// 树形结构展示,懒加载
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("tree")]
- public async Task<List<DepartmentTreeResult>> GetTree(int id = 0)
- {
- return await _departmentRepository.GetTreeAsync(id);
- }
-
- }
- }
|