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