server/aspnetapp/Controllers/WebApi/DepListController.cs
(完整代码) 1KBusing aspnetapp.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace aspnetapp.Controllers.WebApi
{
[Route("api/[controller]")]
[ApiController]
public class DepListController : ControllerBase
{
private readonly CounterContext _context;
public DepListController(CounterContext context)
{
_context = context;
}
[HttpGet]
public async Task<IActionResult> Get()
{
List<CompanyEntity>? allcompany = await _context.Companys.AsNoTracking().OrderBy(s => s.SortNo).ToListAsync().ConfigureAwait(false);
List<DepartmentEntity>? alltopdeps = await _context.Departments.AsNoTracking().Where(s => s.ParentUnid == null).OrderBy(s => s.SortNo).ToListAsync().ConfigureAwait(false);
List<DepartmentEntity>? subdeps = await _context.Departments.AsNoTracking().Where(s => s.ParentUnid != null).OrderBy(s => s.SortNo).ToListAsync().ConfigureAwait(false);
List<object> list = new List<object>() { allcompany.Select(s => new { id = s.Id, name = s.CompanyName }), alltopdeps.Select(s => new { id = s.Id, name = s.DepName, parentId= s.CompanyId }), subdeps.Select(s => new { id = s.Id, name = s.DepName, parentId = s.ParentUnid }) };
return Ok(list);
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。