Update区域更新和新增时是否有重复

This commit is contained in:
2021-05-06 10:52:07 +08:00
parent 9ca1b0a2bf
commit 9146a96130
5 changed files with 25 additions and 10 deletions

View File

@@ -32,6 +32,7 @@ namespace Ewide.Core.Service.Area
public async Task AddAreaCode(AreaCodeInput input)
{
CheckInput(input);
CheckArea(input);
await _areaCodeRep.InsertNowAsync(input.Adapt<SysAreaCode>());
await _sysCacheService.SetAreaCode(await _areaCodeRep.DetachedEntities.ToListAsync());
}
@@ -112,6 +113,7 @@ namespace Ewide.Core.Service.Area
public async Task UpdateAreaCode(AreaCodeInput input)
{
CheckInput(input);
CheckArea(input);
var area = input.Adapt<SysAreaCode>();
await area.UpdateNowAsync();
await _sysCacheService.SetAreaCode(await _areaCodeRep.DetachedEntities.ToListAsync());
@@ -126,5 +128,15 @@ namespace Ewide.Core.Service.Area
//检查是否有子节点
return true;
}
private bool CheckArea(AreaCodeInput input)
{
var any = _areaCodeRep.DetachedEntities.Any(p => p.AdCode == input.AdCode && p.Code != input.Code);
if (any)
{
throw Oops.Oh("区域编码重复");
}
return true;
}
}
}