private static void handle_addr(IAddressSegmentCreator segCreator, AddressLoop container, ISegmentFactory factory, Address address) { if (segCreator.CanProcess(address.AddressType)) { segCreator.AddAddressSegmentsTo(container, factory, address); } }
public void can_create_address_segment() { var container = new AddressLoop(_segFactory); Address addr = get_shipfrom_address(); _addrSegCreator.ForEach(a => handle_addr(a, container, _segFactory, addr)); container.Count(EdiStructureNameConstants.Segment).ShouldEqual(6); addr = get_shipto_address(); _addrSegCreator.ForEach(a => handle_addr(a, container, _segFactory, addr)); container.Count(EdiStructureNameConstants.Segment).ShouldEqual(9); addr = get_billto_address(); _addrSegCreator.ForEach(a => handle_addr(a, container, _segFactory, addr)); container.Count(EdiStructureNameConstants.Segment).ShouldEqual(12); }
protected EDIXmlTransactionSet CreateTransactionSet(OrderShippingInfo message) { if (message.Lines.Count() == 0) { throw new Exception("Shipped order contains no line items!"); } var originalDoc = _docsRepo.GetByDocumentControlNumberAndPartnerID(message.ControlNumber.CastToInt(), BusinessPartner.Initech.Number); if (originalDoc == null) { throw new Exception(string.Format("Control number {0} not found for business partner {1}.", message.ControlNumber, message.BusinessPartnerNumber)); } var orderTypeElement = originalDoc.ResponseElements.Find(e => e.ElementName == "REF02" && (e.Qualifier == Qualifier.MutuallyAssignedCode.Value)); var priorityElement = originalDoc.ResponseElements.Find(e => e.ElementName == "REF02" && (e.Qualifier == Qualifier.ServiceLevelNumber.Value)); var doc = new EDIXmlTransactionSet(_segmentFactory) { ISA = _repo.GetNextISA(GroupTypeConstants.AdvanceShipNotice, BusinessPartner.Initech.Number) }; var docDef = _repo.GetNextDocument(doc.ISA, 856); doc.SetHeader("856", docDef.ControlNumber); docDef.ERPID = message.BOL; _repo.Save(docDef.ISAEntity); doc.AddSegment(get_begin_segment(message)); if (message.MaxDateShipped() > DateTime.MinValue) { doc.AddSegment(_segmentFactory.GetDateTimeSegment(EDIDateQualifiers.Shipped, message.MaxDateShipped())); } var hl = HierarchicalLevelLoopWrapper.BuildWrapper("O", _segmentFactory, true); hl.AddSegment(_segmentFactory.GetPurchaseOrderReference(message.CustomerPO.Trim())); if (orderTypeElement != null) { hl.AddSegment(_segmentFactory.GetReferenceIDSegment(orderTypeElement.Qualifier, orderTypeElement.Value)); } if (priorityElement != null) { hl.AddSegment(_segmentFactory.GetReferenceIDSegment(priorityElement.Qualifier, priorityElement.Value)); } var addrs = new AddressLoop(_segmentFactory); if (message.ShipToAddress.AddressName.IsNullOrEmpty()) { message.ShipToAddress.AddressName = "FEDERAL EXPRESS"; } addrs.AddAddress(message.ShipToAddress, Qualifier.EmptyQualifier); addrs.AddAddress(message.ShipFromAddress, Qualifier.EmptyQualifier); hl.AddLoop(addrs); message.Lines.ForEach(l => add_line(hl, l, originalDoc.LineItems)); hl.AddTo(doc); doc.AddSegment(_segmentFactory.GetTransactionTotal(message.Lines.Count())); doc.SetFooter(); return(doc); }