protected virtual async Task <Shipment> CreateShipmentAsync(CreateOrUpdateShipmentInput input) { var shipment = ObjectMapper.Map <Shipment>(input); CreateOrUpdateOrderItem(input, shipment); await _shipmentManager.CreateAsync(shipment); return(shipment); }
protected virtual async Task <Shipment> UpdateShipmentAsync(CreateOrUpdateShipmentInput input) { var shipment = await _shipmentManager.GetByIdAsync(input.Id); ObjectMapper.Map(input, shipment); await _shipmentManager.ShipmentRepository.EnsureCollectionLoadedAsync(shipment, s => s.Items); CreateOrUpdateOrderItem(input, shipment); await _shipmentManager.UpdateAsync(shipment); return(shipment); }
public async Task <EntityDto <long> > CreateOrUpdateShipment(CreateOrUpdateShipmentInput input) { Shipment shipment = null; if (input.Id > 0) { shipment = await UpdateShipmentAsync(input); } else { shipment = await CreateShipmentAsync(input); } await CurrentUnitOfWork.SaveChangesAsync(); return(new EntityDto <long> { Id = shipment.Id }); }
/// <summary> /// 创建更新物流条目 /// </summary> /// <param name="input"></param> /// <param name="shipment"></param> private void CreateOrUpdateOrderItem(CreateOrUpdateShipmentInput input, Shipment shipment) { if (input.Id == 0) { shipment.Items = new Collection <ShipmentItem>(); } else { var existItemIds = input.Items.Select(i => i.Id).ToList(); var itemsId2Remove = shipment.Items.Where(i => !existItemIds.Contains(i.Id)).ToList(); //删除不存在的属性 foreach (var item in itemsId2Remove) { item.IsDeleted = true; shipment.Items.Remove(item); } } foreach (var itemDto in input.Items) { ShipmentItem item = null; if (itemDto.Id != 0) { item = shipment.Items.FirstOrDefault(i => i.Id == item.Id); } if (item != null) { ObjectMapper.Map(itemDto, item); } else { item = ObjectMapper.Map <ShipmentItem>(itemDto); shipment.Items.Add(item); } } }