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.
85 lines
2.6 KiB
85 lines
2.6 KiB
using AX.FireTrainingSys.Models; |
|
using Microsoft.AspNetCore.Http; |
|
using Microsoft.AspNetCore.Mvc; |
|
using Microsoft.AspNetCore.Mvc.ModelBinding; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Threading.Tasks; |
|
|
|
namespace AX.FireTrainingSys.Controllers.V1 |
|
{ |
|
/// <summary> |
|
/// 建筑特点控制器。 |
|
/// </summary> |
|
[Produces("application/json")] |
|
[Route("api/[controller]")] |
|
[ApiVersion("1.0")] |
|
[ApiController] |
|
public class TemplateBuildingFeaturesController : ControllerBase |
|
{ |
|
private readonly DriveDbContext dbContext; |
|
|
|
public TemplateBuildingFeaturesController(DriveDbContext dbContext) |
|
{ |
|
this.dbContext = dbContext; |
|
} |
|
|
|
/// <summary> |
|
/// 获得指定单位的建筑特点。 |
|
/// </summary> |
|
/// <param name="name">指定的单位名称</param> |
|
/// <returns></returns> |
|
[ProducesResponseType(StatusCodes.Status200OK)] |
|
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
|
[ProducesResponseType(StatusCodes.Status404NotFound)] |
|
[HttpGet] |
|
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name) |
|
{ |
|
if (string.IsNullOrEmpty(name)) |
|
return BadRequest(name); |
|
|
|
var model = await dbContext.TemplateBuildingFeatures.FindAsync(name); |
|
|
|
if (model == null) |
|
return NotFound(name); |
|
|
|
return Ok(model.Content); |
|
} |
|
|
|
/// <summary> |
|
/// 创建或更新指定单位的建筑特点。 |
|
/// </summary> |
|
/// <param name="name">指定的单位名称</param> |
|
/// <param name="content">要保存的内容</param> |
|
[ProducesResponseType(StatusCodes.Status200OK)] |
|
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
|
[HttpPost] |
|
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, [FromBody]string content) |
|
{ |
|
if (string.IsNullOrEmpty(name)) |
|
return BadRequest(name); |
|
|
|
var model = await dbContext.TemplateBuildingFeatures.FindAsync(name); |
|
|
|
if (model == null) |
|
{ |
|
model = new TemplateBuildingFeature |
|
{ |
|
CompanyName = name, |
|
Content = content |
|
}; |
|
|
|
dbContext.TemplateBuildingFeatures.Add(model); |
|
} |
|
else |
|
{ |
|
model.Content = content; |
|
} |
|
|
|
await dbContext.SaveChangesAsync(); |
|
|
|
return Ok(); |
|
} |
|
} |
|
}
|
|
|