69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
using Competition.Common.Util;
|
|
using CompetitionAPI.Util;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CompetitionAPI.Controllers.back
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class RevokeReleaseExamController : Controller
|
|
{
|
|
Competition.Mysql.BLL.pow_exam exam_bll = new Competition.Mysql.BLL.pow_exam();
|
|
|
|
Competition.Mysql.BLL.pow_achievement achievement_bll = new Competition.Mysql.BLL.pow_achievement();
|
|
|
|
public RevokeReleaseExamController()
|
|
{
|
|
|
|
}
|
|
|
|
/// <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)
|
|
{
|
|
var exam_count = exam_bll.GetRecordCount(" ExamId='" + ExamId + "' and Status='已结束' ");
|
|
if (exam_count > 0)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "该考试已结束,不能撤销发布"));
|
|
}
|
|
var count = achievement_bll.GetRecordCount(" ExamId='" + 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, "发生错误,请联系管理员。"));
|
|
}
|
|
}
|
|
}
|
|
}
|