321
This commit is contained in:
parent
66b28bbe72
commit
98dddd684b
|
|
@ -15,12 +15,6 @@ public class DanyeService : IDanyeService
|
||||||
private readonly HoneyBoxDbContext _dbContext;
|
private readonly HoneyBoxDbContext _dbContext;
|
||||||
private readonly ILogger<DanyeService> _logger;
|
private readonly ILogger<DanyeService> _logger;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 标题不可编辑的ID范围(2-20)
|
|
||||||
/// </summary>
|
|
||||||
private const int TitleEditableMinId = 2;
|
|
||||||
private const int TitleEditableMaxId = 20;
|
|
||||||
|
|
||||||
public DanyeService(
|
public DanyeService(
|
||||||
HoneyBoxDbContext dbContext,
|
HoneyBoxDbContext dbContext,
|
||||||
ILogger<DanyeService> logger)
|
ILogger<DanyeService> logger)
|
||||||
|
|
@ -62,7 +56,7 @@ public class DanyeService : IDanyeService
|
||||||
Title = danye.Title,
|
Title = danye.Title,
|
||||||
Content = danye.Content,
|
Content = danye.Content,
|
||||||
IsImageOptimizer = danye.IsImageOptimizer == 1,
|
IsImageOptimizer = danye.IsImageOptimizer == 1,
|
||||||
IsTitleEditable = !IsTitleProtected(danye.Id)
|
IsTitleEditable = true // 所有单页标题都可编辑
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,18 +76,10 @@ public class DanyeService : IDanyeService
|
||||||
throw new BusinessException(BusinessErrorCodes.ValidationFailed, "内容不能为空");
|
throw new BusinessException(BusinessErrorCodes.ValidationFailed, "内容不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新标题(仅当ID不在2-20范围内且提供了标题时)
|
// 更新标题
|
||||||
if (!string.IsNullOrWhiteSpace(request.Title))
|
if (!string.IsNullOrWhiteSpace(request.Title))
|
||||||
{
|
{
|
||||||
if (IsTitleProtected(id))
|
danye.Title = request.Title;
|
||||||
{
|
|
||||||
_logger.LogWarning("尝试修改受保护的单页标题: Id={Id}", id);
|
|
||||||
// 不抛出异常,只是忽略标题更新
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
danye.Title = request.Title;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新内容
|
// 更新内容
|
||||||
|
|
@ -156,12 +142,6 @@ public class DanyeService : IDanyeService
|
||||||
throw new BusinessException(BusinessErrorCodes.NotFound, "单页不存在");
|
throw new BusinessException(BusinessErrorCodes.NotFound, "单页不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 系统预设单页(ID 2-20)不允许删除
|
|
||||||
if (IsTitleProtected(id))
|
|
||||||
{
|
|
||||||
throw new BusinessException(BusinessErrorCodes.ValidationFailed, "系统预设单页不允许删除");
|
|
||||||
}
|
|
||||||
|
|
||||||
_dbContext.Danyes.Remove(danye);
|
_dbContext.Danyes.Remove(danye);
|
||||||
var result = await _dbContext.SaveChangesAsync() > 0;
|
var result = await _dbContext.SaveChangesAsync() > 0;
|
||||||
|
|
||||||
|
|
@ -172,14 +152,6 @@ public class DanyeService : IDanyeService
|
||||||
|
|
||||||
#region Private Helper Methods
|
#region Private Helper Methods
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 判断标题是否受保护(ID 2-20 的单页标题不可编辑)
|
|
||||||
/// </summary>
|
|
||||||
private static bool IsTitleProtected(int id)
|
|
||||||
{
|
|
||||||
return id >= TitleEditableMinId && id <= TitleEditableMaxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unix时间戳转DateTime
|
/// Unix时间戳转DateTime
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user