CompetitionAPI_dotnet/CompetitionAPI/Controllers/unity/UpdateEnclosureController.cs

77 lines
2.8 KiB
C#

using Competition.Common.Util;
using CompetitionAPI.api.unity;
using CompetitionAPI.Util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace CompetitionAPI.Controllers.unity
{
[Route("unity/[controller]")]
[ApiController]
public class UpdateEnclosureController : Controller
{
Competition.Mysql.BLL.pow_user_exam user_exam_bll = new Competition.Mysql.BLL.pow_user_exam();
Competition.Mysql.BLL.pow_config config_bll = new Competition.Mysql.BLL.pow_config();
public UpdateEnclosureController()
{
}
/// <summary>
/// 更新围栏放置状态接口
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[Authorize]
[HttpPost]
[APIFilter]
public JsonResult Index([FromForm] UpdateEnclosureRequest req)
{
try
{
var config_model = config_bll.GetModelList("").FirstOrDefault();
if (config_model == null)
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "配置信息不存在"));
}
var user_exam_model = user_exam_bll.GetModelList(" ExamId='" + req.ExamId + "' and UserId='" + req.UserId + "' ").FirstOrDefault();
if (user_exam_model != null)
{
if (user_exam_model.Status == "已结束")
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "考生考试已结束"));
}
var enclosure_fault_score = decimal.Parse(config_model.EnclosureFaultScore);
var value = decimal.Parse(user_exam_model.EnclosureIsScore) - enclosure_fault_score;
if (value < 0)
{
value = 0;
}
user_exam_model.EnclosureIsScore = value.ToString();
if (user_exam_bll.UpdateExamEnclosure(user_exam_model.UserExamId, user_exam_model.EnclosureIsScore))
{
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, "发生错误,请联系管理员。"));
}
}
}
}