public IHttpActionResult SyncAllInvoicesByVendor([FromUri] string vendor)
        {
            var service = new QBOServiceManager();

            service.SyncInvoiceFromQBO(vendor);

            return(Created(Request.RequestUri, "Sync Success!"));
        }
Example #2
0
        public IHttpActionResult SyncInvoiceToQBO([FromUri] int invoiceId)
        {
            var invoiceInDb = _context.Invoices
                              .Include(x => x.InvoiceDetails)
                              .SingleOrDefault(x => x.Id == invoiceId);

            //使用Refresh token刷新或得新鲜的Access Token
            var userId = User.Identity.GetUserId <string>();

            System.Threading.Tasks.Task.Run(async() => { await _intuitOAuth.RefreshToken(userId); }).Wait();

            //同步invoice到QBO中
            var service = new QBOServiceManager();

            var invoiceResult = service.SyncInvoiceToQBO(invoiceId);

            invoiceInDb.InvoiceNumber = invoiceResult.Invoice.DocNumber;
            invoiceInDb.UploadedDate  = invoiceResult.Time;
            invoiceInDb.UploadedBy    = _userName;

            _context.SaveChanges();

            return(Created(Request.RequestUri, "Sync Success!"));
        }