private TombstoneBuriedPeopleMapDTO LoadEntityData(TombstoneBuriedPeopleMap entity, bool includeAll) { var myDto = new TombstoneBuriedPeopleMapDTO() { Id = entity.Id, BuriedCustomerId = entity.BuriedCustomerId, TombstoneId = entity.TombstoneId, Remark = entity.Remark }; //包括所有关系 if (includeAll) { if (entity.BuriedCustomerId > 0) { myDto.BuriedCustomer = null; } if (entity.TombstoneId > 0) { myDto.Tombstone = null; } } return(myDto); }
/// <summary> /// 墓碑落葬 /// </summary> /// <param name="tombstoneId"></param> /// <param name="customerIds"></param> /// <returns></returns> public DataControlResult <TombstoneBuriedPeopleMapDTO> BuryPeopleTombstone(int tombstoneId, List <int> customerIds) { var result = new DataControlResult <TombstoneBuriedPeopleMapDTO>(); try { using (TransactionScope tsScope = new TransactionScope()) { var submitFlag = true; foreach (var customerId in customerIds) { var tombstoneBuriedPeopleMap = new TombstoneBuriedPeopleMap { TombstoneId = tombstoneId, BuriedCustomerId = customerId }; //判断该墓碑是否存在落葬关系? 存在解除再落葬 var tombRepeats = _databaseContext.TombstoneBuriedPeopleMaps.Where(a => a.TombstoneId == tombstoneId); foreach (var tombRepeat in tombRepeats) { _databaseContext.TombstoneBuriedPeopleMaps.Remove(tombRepeat); } //判断该客户是否存在落葬关系 var repeat = _databaseContext.TombstoneBuriedPeopleMaps.FirstOrDefault(a => a.BuriedCustomerId == customerId); if (repeat != null && repeat.TombstoneId != tombstoneId) { var customer = _databaseContext.Customers.FirstOrDefault(a => a.Id == customerId); var fullName = customer != null ? customer.LastName + customer.MiddleName + customer.FirstName : "未知"; result.code = MyErrorCode.ResDBError; result.msg = "客户:" + fullName + "(" + customerId + ")" + "已经落葬,如需更改请先解除落葬关系"; result.success = false; result.ResultOutDto = null; submitFlag = false; break; } _databaseContext.TombstoneBuriedPeopleMaps.Add(tombstoneBuriedPeopleMap); result.ResultOutDtos.Add(_tombstoneBuriedPeopleMapMapper.Map(tombstoneBuriedPeopleMap, false)); } _databaseContext.SaveChanges(); if (submitFlag) { tsScope.Complete(); result.code = MyErrorCode.ResOK; result.msg = string.Empty; result.success = true; } } return(result); } catch (Exception ex) { result.code = MyErrorCode.ResDBError; result.msg = ex.Message; result.success = false; return(result); } return(result); }
public TombstoneBuriedPeopleMapDTO Map(TombstoneBuriedPeopleMap entity, bool includeAll) { var dto = LoadEntityData(entity, includeAll); return(dto); }