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 { /// /// 职务控制器。 /// [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; } /// /// 获得所有职务。 /// /// [ProducesResponseType(StatusCodes.Status200OK)] [HttpGet] public async Task>> 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 }; } }