73 lines
2.5 KiB
C#
73 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.study
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class EditStudyClassController : Controller
|
|
{
|
|
Competition.Mysql.BLL.pow_study_class study_class_bll = new Competition.Mysql.BLL.pow_study_class();
|
|
|
|
private static Object Lockobj = new object();
|
|
|
|
public EditStudyClassController()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑学习分类接口
|
|
/// </summary>
|
|
/// <param name="req">请求参数</param>
|
|
/// <returns></returns>
|
|
[Authorize]
|
|
[HttpPost]
|
|
[APIFilter]
|
|
public JsonResult Index([FromBody] EditStudyClassRequest req)
|
|
{
|
|
try
|
|
{
|
|
lock (Lockobj)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(req.StudyClassId))
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "学习分类id不能为空"));
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(req.StudyClassName))
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "学习分类名称不能为空"));
|
|
}
|
|
|
|
if (study_class_bll.GetRecordCount(string.Format(" StudyClassName = '{0}' and StudyClassId != '{1}'", req.StudyClassName, req.StudyClassId)) > 0)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "学习分类名称禁止重复"));
|
|
}
|
|
|
|
var model = study_class_bll.GetModel(req.StudyClassId);
|
|
model.StudyClassName = req.StudyClassName;
|
|
|
|
if (study_class_bll.Update(model))
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Success, "编辑成功"));
|
|
}
|
|
else
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "编辑失败"));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。"));
|
|
}
|
|
}
|
|
}
|
|
}
|