update 房屋编码保存

This commit is contained in:
2021-05-20 09:11:53 +08:00
parent 9bd6446a76
commit 4ddf8b7431
4 changed files with 15 additions and 19 deletions

View File

@@ -14,7 +14,8 @@ namespace Ewide.Application.Service.HouseCode.Dto
public class AddHouseCodeInput : PageInputBase
{
[Required(ErrorMessage = "区域编码不能为空")]
public string FullNumber { get; set; }
[Required(ErrorMessage = "行政区域编码不能为空")]
public string AreaCode { get; set; }
[Required(ErrorMessage = "项目Id不能为空")]
public string ProjectId { get; set; }

View File

@@ -1,5 +1,6 @@
using Ewide.Application.Entity;
using Ewide.Application.Service.HouseCode.Dto;
using Ewide.Core;
using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
@@ -26,8 +27,12 @@ namespace Ewide.Application.Service.HouseCode
[HttpPost("/houseCode/add")]
public async Task AddHouseCode(AddHouseCodeInput input)
{
var areaCodeRep = Db.GetRepository<SysAreaCode>();
var areaCode = areaCodeRep.DetachedEntities.Where(a => a.Code == input.AreaCode).FirstOrDefault();
if(areaCode == null) throw Oops.Oh("区域编码有误,添加失败");
input.FullNumber = areaCode.AdCode + input.No;
var houseCode = input.Adapt<BsHouseCode>();
var isExist = await _houseCodeRep.AnyAsync(p => p.AreaCode == houseCode.AreaCode && p.ProjectId == houseCode.ProjectId && p.No == houseCode.No);
var isExist = await _houseCodeRep.AnyAsync(p => p.FullNumber == houseCode.FullNumber);
if (isExist) throw Oops.Oh("房屋编码已存在,不可重复添加");
await _houseCodeRep.InsertAsync(houseCode);
}