Commit f9b4e17e by yiyu.li
parents a07dad2b 7ca6b796
...@@ -248,11 +248,16 @@ namespace Siger.ApiACC.Controllers ...@@ -248,11 +248,16 @@ namespace Siger.ApiACC.Controllers
[HttpGet] [HttpGet]
public IActionResult Delete(int id) public IActionResult Delete(int id)
{ {
var entity = _toolsRepository.Get(q => q.projectId == ProjectId && q.id == id); var entity = _toolsAssemblyRepository.Get(q => q.projectId == ProjectId && q.id == id);
if (entity == null) if (entity == null)
{ {
throw new BadRequestException(CommonEnum.RecordNotFound); throw new BadRequestException(CommonEnum.RecordNotFound);
} }
var sons = _toolsAssemblyRepository.GetList(q => q.projectId == ProjectId && q.parent == entity.son).ToList();
foreach(var son in sons)
{
_toolsAssemblyRepository.Delete(son);
}
_toolsAssemblyRepository.Delete(entity); _toolsAssemblyRepository.Delete(entity);
if (_unitOfWork.Commit() > 0) if (_unitOfWork.Commit() > 0)
{ {
...@@ -276,14 +281,24 @@ namespace Siger.ApiACC.Controllers ...@@ -276,14 +281,24 @@ namespace Siger.ApiACC.Controllers
{ {
throw new BadRequestException(CommonEnum.RecordNotFound); throw new BadRequestException(CommonEnum.RecordNotFound);
} }
var sons = _toolsAssemblyRepository.GetList(q => q.projectId == ProjectId && entities.Select(t => t.son).Contains(q.parent)).ToList();
foreach (var son in sons)
{
_toolsAssemblyRepository.Delete(son);
}
foreach (var entity in entities) foreach (var entity in entities)
{ {
_toolsAssemblyRepository.Delete(entity); _toolsAssemblyRepository.Delete(entity);
} }
if (_unitOfWork.Commit() > 0) if (_unitOfWork.Commit() > 0)
{
return new ObjectResult(CommonEnum.Succefull); return new ObjectResult(CommonEnum.Succefull);
}
else
{
throw new BadRequestException(CommonEnum.Fail); throw new BadRequestException(CommonEnum.Fail);
} }
} }
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment