isRuleChange
This commit is contained in:
parent
3a94e926c7
commit
c2908c982b
@ -74,7 +74,7 @@ namespace asg_form.Controllers
|
||||
[Authorize]
|
||||
[Route("api/v1/admin/Events")]
|
||||
[HttpPut]
|
||||
public async Task<ActionResult<List<T_events>>> putevent(int eventId, [FromBody] T_events_debug events)
|
||||
public async Task<ActionResult<List<T_events>>> putevent(int eventId, string isRuleChange="0", [FromBody] T_events_debug events)
|
||||
{
|
||||
|
||||
if (this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
|
||||
@ -82,7 +82,7 @@ namespace asg_form.Controllers
|
||||
|
||||
TestDbContext testDb = new TestDbContext();
|
||||
var eve = testDb.events.FirstOrDefault(a => a.Id == eventId);
|
||||
if(eve==null) return BadRequest(new error_mb { code = 404, message = "没有找到对应信息" });
|
||||
if (eve == null) return BadRequest(new error_mb { code = 404, message = "没有找到对应信息" });
|
||||
eve.name = events.name;
|
||||
eve.opentime = events.opentime;
|
||||
eve.is_over = events.is_over;
|
||||
@ -90,35 +90,38 @@ namespace asg_form.Controllers
|
||||
eve.status = events.status;
|
||||
eve.config = events.config;
|
||||
|
||||
if (!string.IsNullOrEmpty(events.rule_markdown))
|
||||
if (isRuleChange == "1")
|
||||
{
|
||||
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "doc", "rule", $"{eve.name}.md");
|
||||
if (!string.IsNullOrEmpty(events.rule_markdown))
|
||||
{
|
||||
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "doc", "rule", $"{eve.name}.md");
|
||||
|
||||
// 如果文件存在,删除旧文件
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
}
|
||||
// 如果文件存在,删除旧文件
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
}
|
||||
|
||||
// 创建目录(如果不存在的话)
|
||||
var directoryPath = Path.GetDirectoryName(filePath);
|
||||
if (!Directory.Exists(directoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
}
|
||||
// 创建目录(如果不存在的话)
|
||||
var directoryPath = Path.GetDirectoryName(filePath);
|
||||
if (!Directory.Exists(directoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
}
|
||||
|
||||
// 写入新的规则内容
|
||||
try
|
||||
{
|
||||
await System.IO.File.WriteAllTextAsync(filePath, events.rule_markdown);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, new error_mb { code = 500, message = "文件操作失败: " + ex.Message });
|
||||
// 写入新的规则内容
|
||||
try
|
||||
{
|
||||
await System.IO.File.WriteAllTextAsync(filePath, events.rule_markdown);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, new error_mb { code = 500, message = "文件操作失败: " + ex.Message });
|
||||
}
|
||||
}
|
||||
await testDb.SaveChangesAsync();
|
||||
return Ok(eve);
|
||||
}
|
||||
await testDb.SaveChangesAsync();
|
||||
return Ok(eve);
|
||||
}
|
||||
return Ok(new error_mb { code = 401, message = "无权访问" });
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user