72 lines
2.5 KiB
C#
72 lines
2.5 KiB
C#
using Competition.Common.Util;
|
|
using CompetitionAPI.Util;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CompetitionAPI.Controllers.back
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class ReleaseExamController : Controller
|
|
{
|
|
Competition.Mysql.BLL.pow_exam exam_bll = new Competition.Mysql.BLL.pow_exam();
|
|
|
|
Competition.Mysql.BLL.pow_exam_fault exam_fault_bll = new Competition.Mysql.BLL.pow_exam_fault();
|
|
|
|
public ReleaseExamController()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发布考试接口
|
|
/// </summary>
|
|
/// <param name="ExamId">考试id</param>
|
|
/// <returns></returns>
|
|
[Authorize]
|
|
[HttpGet]
|
|
[APIFilter]
|
|
public JsonResult Index(string ExamId)
|
|
{
|
|
try
|
|
{
|
|
var exam_model = exam_bll.GetModel(ExamId);
|
|
if (exam_model != null)
|
|
{
|
|
if (exam_model.Type == "考试")
|
|
{
|
|
if (exam_model.StartExamTime < DateTime.Now)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "考试开始时间小于当前时间,不允许发布"));
|
|
}
|
|
}
|
|
var count = exam_fault_bll.GetRecordCount(string.Format(" ExamId='{0}' and ChoiceQuestion!='0' ", ExamId));
|
|
if (count == 0)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "未设置一条故障数据,不允许发布"));
|
|
}
|
|
if (exam_bll.UpdateRelease(ExamId, "已发布"))
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Success, "发布成功"));
|
|
}
|
|
else
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "发布失败"));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "未找到考试信息"));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。"));
|
|
}
|
|
}
|
|
}
|
|
}
|