消防培训系统服务器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

using AX.FireTrainingSys.DTOs;
using AX.FireTrainingSys.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace AX.FireTrainingSys.Controllers
{
/// <summary>
/// 职务控制器。
/// </summary>
[Produces("application/json")]
[Route("api/[controller]")]
[ApiVersion("1.0")]
[ApiController]
public class PostsController : ControllerBase
{
private readonly DriveDbContext dbContext;
public PostsController(DriveDbContext dbContext)
{
this.dbContext = dbContext;
}
/// <summary>
/// 获得所有职务。
/// </summary>
/// <returns></returns>
[ProducesResponseType(StatusCodes.Status200OK)]
[HttpGet]
public async Task<ActionResult<List<PostInfo>>> Get()
{
var result = await dbContext.Posts
.AsNoTracking()
.Select(e => e.ToDTO())
.ToListAsync();
return Ok(result);
}
}
internal static partial class Extensions
{
public static PostInfo ToDTO(this Post model) => new PostInfo { Id = model.Id, Name = model.Name };
}
}