namespace Tiobon.Core.Api.Controllers; /// /// 题目(Controller) /// [Route("api/[controller]")] [ApiController, GlobalActionFilter] [Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghre)] public class Ghre_QuestionController : BaseController { IGhre_QuestionAnswerServices _ghre_QuestionAnswerServices; public Ghre_QuestionController(IGhre_QuestionServices service, IGhre_QuestionAnswerServices ghre_QuestionAnswerServices) : base(service) { _ghre_QuestionAnswerServices = ghre_QuestionAnswerServices; } #region 基础接口 #region 新增 /// /// 新增数据 /// /// /// [HttpPost("Insert")] public override async Task> 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(null, "新增成功"); data.Success = id > 0; if (data.Success) data.Data = id.ObjToString(); else return Failed("新增失败"); return data; } #endregion #region 更新 /// /// 更新数据 /// /// 主键ID /// /// [HttpPost("Update/{Id}")] public override async Task 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 }