77 lines
2.5 KiB
C#
77 lines
2.5 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;
|
|
|
|
namespace CompetitionAPI.Controllers.back.room
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class AddRoomIPController : Controller
|
|
{
|
|
Competition.Mysql.BLL.admin_ip ip_bll = new Competition.Mysql.BLL.admin_ip();
|
|
|
|
private static Object Lockobj = new object();
|
|
|
|
public AddRoomIPController()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增考场IP数据接口
|
|
/// </summary>
|
|
/// <param name="req">请求数据</param>
|
|
/// <returns></returns>
|
|
[Authorize]
|
|
[HttpPost]
|
|
[APIFilter]
|
|
public JsonResult Index([FromBody] AddRoomIPRequest req)
|
|
{
|
|
try
|
|
{
|
|
lock (Lockobj)
|
|
{
|
|
if (req != null)
|
|
{
|
|
if (string.IsNullOrEmpty(req.IP))
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "IP不能为空"));
|
|
}
|
|
|
|
if (ip_bll.GetRecordCount(string.Format(" IP = '{0}' ", req.IP)) > 0)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "IP禁止重复"));
|
|
}
|
|
|
|
//设备名称唯一
|
|
Competition.Mysql.Model.admin_ip model = new Competition.Mysql.Model.admin_ip();
|
|
model.Id = Tool.GetLongId();
|
|
model.IP = req.IP;
|
|
model.CreateTime = DateTime.Now;
|
|
if (ip_bll.Add(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, "发生错误,请联系管理员。"));
|
|
}
|
|
}
|
|
}
|
|
}
|