79 lines
2.6 KiB
C#
79 lines
2.6 KiB
C#
using Competition.Common.Util;
|
|
using CompetitionAPI.api.back;
|
|
using CompetitionAPI.Util;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
namespace CompetitionAPI.Controllers.back.room
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class EditRoomIPController : Controller
|
|
{
|
|
Competition.Mysql.BLL.admin_ip ip_bll = new Competition.Mysql.BLL.admin_ip();
|
|
|
|
private static Object Lockobj = new object();
|
|
|
|
public EditRoomIPController()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑考场IP数据接口
|
|
/// </summary>
|
|
/// <param name="req">请求数据</param>
|
|
/// <returns></returns>
|
|
[Authorize]
|
|
[HttpPost]
|
|
[APIFilter]
|
|
public JsonResult Index([FromBody] EditRoomIPRequest req)
|
|
{
|
|
try
|
|
{
|
|
lock (Lockobj)
|
|
{
|
|
if (req != null)
|
|
{
|
|
if (string.IsNullOrEmpty(req.Id))
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "考场IP的id不能为空"));
|
|
}
|
|
if (string.IsNullOrEmpty(req.IP))
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "IP不能为空"));
|
|
}
|
|
|
|
if (ip_bll.GetRecordCount(string.Format(" IP = '{0}' and id != {1}", req.IP, req.Id)) > 0)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "IP禁止重复"));
|
|
}
|
|
|
|
Competition.Mysql.Model.admin_ip model = ip_bll.GetModel(req.Id);
|
|
model.IP = req.IP;
|
|
if (ip_bll.Update(model))
|
|
{
|
|
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, "发生错误,请联系管理员。"));
|
|
}
|
|
}
|
|
}
|
|
}
|