/// <summary> /// 插入新订单行 /// </summary> /// <param name="order">订单</param> /// <param name="dto">订单DTO</param> /// <param name="line">订单行DTO</param> /// <param name="importType">引进方式</param> /// <param name="supplierId">供应商ID</param> private void InsertOrderLine(EngineLeaseOrder order, EngineLeaseOrderDTO dto, EngineLeaseOrderLineDTO line, ActionCategory importType, int supplierId) { // 获取飞机物料机型 var material = _materialRepository.GetFiltered(m => m.Id == line.EngineMaterialId) .OfType<EngineMaterial>() .FirstOrDefault(); var pnReg = _pnRegRepository.GetFiltered(p => p.Pn == material.Pn).FirstOrDefault(); if (material == null) { throw new ArgumentException("未能获取飞机物料!"); } // 添加订单行 var orderLine = order.AddNewEngineLeaseOrderLine(line.UnitPrice, line.Amount, line.Discount, line.EstimateDeliveryDate); orderLine.SetEngineMaterial(line.EngineMaterialId); // 创建或引用合同发动机 var persist = _contractEngineRepository.Get(line.ContractEngineId) as LeaseContractEngine; var contractEngine = ContractEngineFactory.CreateLeaseContractEngine(dto.Name, line.RankNumber); contractEngine.ChangeCurrentIdentity(line.ContractEngineId); contractEngine.SetImportCategory(importType); contractEngine.SetSerialNumber(line.SerialNumber); contractEngine.SetSupplier(supplierId); contractEngine.SetPart(pnReg); if (persist == null) { orderLine.SetContractEngine(contractEngine); } else { orderLine.SetContractEngine(persist); _contractEngineRepository.Merge(persist, contractEngine); } }
/// <summary> /// 更新订单行 /// </summary> /// <param name="line">订单行DTO</param> /// <param name="orderLine">订单行</param> private void UpdateOrderLine(EngineLeaseOrderLineDTO line, EngineLeaseOrderLine orderLine) { // 获取飞机物料机型 var material = _materialRepository.GetFiltered(m => m.Id == line.EngineMaterialId) .OfType<EngineMaterial>() .FirstOrDefault(); var pnReg = _pnRegRepository.GetFiltered(p => p.Pn == material.Pn).FirstOrDefault(); if (material == null) { throw new ArgumentException("未能获取飞机物料!"); } // 更新订单行 orderLine.UpdateOrderLine(line.UnitPrice, line.Amount, line.Discount, line.EstimateDeliveryDate); orderLine.SetEngineMaterial(line.EngineMaterialId); // 更新合同发动机 var contractEngine = _contractEngineRepository.Get(orderLine.ContractEngineId); contractEngine.SetRankNumber(line.RankNumber); contractEngine.SetSerialNumber(line.SerialNumber); contractEngine.SetPart(pnReg); }