41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using Ewide.Application.Entity;
|
|
using Ewide.Application.Service.HouseCode.Dto;
|
|
using Ewide.Core;
|
|
using Furion.DatabaseAccessor;
|
|
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Furion.FriendlyException;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Ewide.Application.Service.HouseCode
|
|
{
|
|
public class HouseCodeService : IHouseCodeService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly IRepository<BsHouseCode> _houseCodeRep;
|
|
|
|
public HouseCodeService(IRepository<BsHouseCode> HouseCodeRep)
|
|
{
|
|
_houseCodeRep = HouseCodeRep;
|
|
}
|
|
|
|
[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.FullNumber == houseCode.FullNumber);
|
|
if (isExist) throw Oops.Oh("房屋编码已存在,不可重复添加");
|
|
await _houseCodeRep.InsertAsync(houseCode);
|
|
}
|
|
}
|
|
}
|