private static async Task <TSDESADV> BuildDespatchAdviceForOrder(TSORDERS ediItem, IEnumerable <string> serialNumbers, string controlNumber) { switch (ediItem.BGM.Messagefunctioncoded_03) { case "9": case "4": return(await DespatchAdviceShipmentBuilder.BuildDespatchAdvice(controlNumber, ediItem, serialNumbers)); case "38": return(DespatchAdviceGRBuilder.BuildDespatchAdvice(controlNumber, ediItem, serialNumbers)); } throw new ArgumentException("Unknown order type " + ediItem.BGM.Messagefunctioncoded_03); }
private static async Task WriteEdiFactAsnResponse(IEdiItem ediItem, IEnumerable <string> serialNumbers, string responseFilePath) { var controlNumber = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds().ToString(); var transaction = ediItem is TSORDERS item ? (await BuildDespatchAdviceForOrder(item, serialNumbers, controlNumber)) : DespatchAdviceGRBuilder.BuildDespatchAdvice(controlNumber, (TSDESADV)ediItem); using (var stream = File.Create(responseFilePath)) { using (var writer = new EdifactWriter(stream, new EdifactWriterSettings { Encoding = Encoding.Default })) { writer.Write(Separators.Edifact.ToUna()); writer.Write(EDIFactSegmentBuilders.BuildUnb(controlNumber)); writer.Write(transaction); } } }