Esempio n. 1
0
        /// <summary>
        /// Save to DB with code first - this will create a new database the first time
        /// Edit the connection string in app.config, by default it looks for a local SQL Server instance
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            Stream ediStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\X12\PurchaseOrder.txt");

            List <IEdiItem> ediItems;

            using (var ediReader = new X12Reader(ediStream, "EdiFabric.Templates.X12"))
                ediItems = ediReader.ReadToEnd().ToList();

            var purchaseOrders = ediItems.OfType <TS850>();

            using (var db = new X12Context())
            {
                foreach (var purchaseOrder in purchaseOrders)
                {
                    purchaseOrder.ClearCache();
                    db.TS850.Add(purchaseOrder);
                }
                db.SaveChanges();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Pull the last purchase order from DB
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            using (var db = new X12Context())
            {
                var po = db.TS850.OrderByDescending(o => o.Id).FirstOrDefault();

                using (var stream = new MemoryStream())
                {
                    using (var writer = new X12Writer(stream))
                    {
                        writer.Write(SegmentBuilders.BuildIsa("1"));
                        writer.Write(SegmentBuilders.BuildGs("1"));
                        writer.Write(po);
                    }

                    Debug.Write(stream.LoadToString());
                }
            }
        }