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.
100 lines
3.1 KiB
100 lines
3.1 KiB
namespace Tiobon.Core.Api.Controllers;
|
|
|
|
/// <summary>
|
|
/// 题目(Controller)
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController, GlobalActionFilter]
|
|
[Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghre)]
|
|
public class Ghre_QuestionController : BaseController<IGhre_QuestionServices, Ghre_Question, Ghre_QuestionDto, InsertGhre_QuestionInput, EditGhre_QuestionInput>
|
|
{
|
|
|
|
IGhre_QuestionAnswerServices _ghre_QuestionAnswerServices;
|
|
public Ghre_QuestionController(IGhre_QuestionServices service, IGhre_QuestionAnswerServices ghre_QuestionAnswerServices) : base(service)
|
|
{
|
|
_ghre_QuestionAnswerServices = ghre_QuestionAnswerServices;
|
|
}
|
|
|
|
#region 基础接口
|
|
#region 查询
|
|
|
|
/// <summary>
|
|
/// 根据Id查询数据
|
|
/// </summary>
|
|
/// <param name="Id">主键ID</param>
|
|
/// <returns></returns>
|
|
[HttpPost("Query/{Id}")]
|
|
public override async Task<ServiceResult<Ghre_QuestionDto>> QueryById(long Id)
|
|
{
|
|
var entity = await _service.QueryById(Id);
|
|
entity.Answers = await _ghre_QuestionAnswerServices.Query(x => x.QuestionId == Id, "TaxisNo ASC");
|
|
if (entity is null)
|
|
return Failed<Ghre_QuestionDto>("获取失败", 500);
|
|
else
|
|
return Success(entity, "获取成功");
|
|
}
|
|
#endregion
|
|
|
|
#region 新增
|
|
/// <summary>
|
|
/// 新增数据
|
|
/// </summary>
|
|
/// <param name="insertModel"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Insert")]
|
|
public override async Task<ServiceResult<string>> Insert([FromBody] InsertGhre_QuestionInput insertModel)
|
|
{
|
|
insertModel.CourseIds = string.Join(";", insertModel.CourseId.Select(x => x));
|
|
var id = await _service.Add(insertModel);
|
|
var answers = insertModel.Answers;
|
|
if (answers.Any())
|
|
{
|
|
int i = 100;
|
|
answers.ForEach(x =>
|
|
{
|
|
x.TaxisNo = i;
|
|
x.QuestionId = id;
|
|
});
|
|
i = i + 100;
|
|
await _ghre_QuestionAnswerServices.Add(answers);
|
|
}
|
|
var data = Success<string>(null, "新增成功");
|
|
data.Success = id > 0;
|
|
if (data.Success)
|
|
data.Data = id.ObjToString();
|
|
else
|
|
return Failed<string>("新增失败");
|
|
return data;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 更新
|
|
/// <summary>
|
|
/// 更新数据
|
|
/// </summary>
|
|
/// <param name="Id">主键ID</param>
|
|
/// <param name="editModel"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Update/{Id}")]
|
|
public override async Task<ServiceResult> Put(long Id, [FromBody] EditGhre_QuestionInput editModel)
|
|
{
|
|
await _ghre_QuestionAnswerServices.Delete(x => x.QuestionId == Id);
|
|
var answers = editModel.Answers;
|
|
if (answers.Any())
|
|
{
|
|
int i = 100;
|
|
answers.ForEach(x =>
|
|
{
|
|
x.TaxisNo = i;
|
|
x.QuestionId = Id;
|
|
});
|
|
i = i + 100;
|
|
await _ghre_QuestionAnswerServices.Add(answers);
|
|
}
|
|
return await base.Put(Id, editModel);
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
} |