public ActionResult <InhabitantAndHouseInfoAddResViewModel> ResidentAndHouseInfo_Manage_OpinionInfo_Add(InhabitantAndHouseInfoAddViewModel inhabitantAndHouseInfoAddViewModel) { inhabitantAndHouseInfoAddViewModel.inhabitantAndHouseInfoAddMiddles[0].HouseId = Guid.NewGuid(); //添加房子信息 var temp = _houseInfoService.AddHouseInfoSingle(inhabitantAndHouseInfoAddViewModel.inhabitantAndHouseInfoAddMiddles[0]); InhabitantAndHouseInfoAddResViewModel inhabitantAndHouseInfoAddResViewModel = new InhabitantAndHouseInfoAddResViewModel(); if (temp == 0) { inhabitantAndHouseInfoAddResViewModel.baseViewModel.IsSuccess = false; inhabitantAndHouseInfoAddResViewModel.AddCount = 0; inhabitantAndHouseInfoAddResViewModel.baseViewModel.Message = "添加失败"; inhabitantAndHouseInfoAddResViewModel.baseViewModel.ResponseCode = 200; _ILogger.Information("地址重复,添加失败"); return(Ok(inhabitantAndHouseInfoAddResViewModel)); } var houseId = inhabitantAndHouseInfoAddViewModel.inhabitantAndHouseInfoAddMiddles[0].HouseId; int InhabitantAndHouseInfo_add_Count = 0; var opinionInfoAddResModel = _inhabitantFactory.GetInhabitantAndHouseInfoAddResViewModel(); foreach (InhabitantAndHouseInfoAddMiddle model in inhabitantAndHouseInfoAddViewModel.inhabitantAndHouseInfoAddMiddles) { //验证居民是否重复 var checkInhabitant = _inhabitantService.Inhabitant_ByIdNo_Search(model.IdNumber); if (checkInhabitant != null) { model.HouseId = houseId; model.RelationShipId = Guid.NewGuid(); //如果居民存在,把model的id 设置成查出的居民id model.InhabitantId = checkInhabitant.Id; //添加居民和房子关系 _houseInfoRelationShipService.AddHouseInfoRelationShipSingle(model); InhabitantAndHouseInfo_add_Count++; } else { model.HouseId = houseId; model.RelationShipId = Guid.NewGuid(); model.InhabitantId = Guid.NewGuid(); //添加居民信息 _inhabitantService.AddInhabitantSingle(model); //添加居民和房子关系 _houseInfoRelationShipService.AddHouseInfoRelationShipSingle(model); InhabitantAndHouseInfo_add_Count++; //添加党员信息 if (model.Politics == "中共党员") { PartyInfoAddViewModel partyInfoAddViewModel = new PartyInfoAddViewModel(); partyInfoAddViewModel.ResidentId = model.InhabitantId; partyInfoAddViewModel.IdNumber = model.IdNumber; int Party_add_Count = 0; Party_add_Count = _partyService.AddPartyInfo(partyInfoAddViewModel); } } } if (InhabitantAndHouseInfo_add_Count > 0) { opinionInfoAddResModel.baseViewModel.IsSuccess = true; opinionInfoAddResModel.AddCount = InhabitantAndHouseInfo_add_Count; opinionInfoAddResModel.baseViewModel.Message = "添加成功"; opinionInfoAddResModel.baseViewModel.ResponseCode = 200; _ILogger.Information("增添信息成功"); return(Ok(opinionInfoAddResModel)); } else { opinionInfoAddResModel.baseViewModel.IsSuccess = false; opinionInfoAddResModel.AddCount = 0; opinionInfoAddResModel.baseViewModel.Message = "添加失败"; opinionInfoAddResModel.baseViewModel.ResponseCode = 400; _ILogger.Information("增添信息失败"); return(BadRequest(opinionInfoAddResModel)); } }