コード例 #1
0
ファイル: ProcessError.cs プロジェクト: krisburtoft/QBWC
        public static void ProcessFailedOrder(int requestID, string xmlMessage)
        {
            var rep = new Repository();
            var failure = new FailedOrder()
            {
                Imported = false,
                RequestID = requestID,
                OrderID = rep.GetQuickBooksOrderByRequestID(requestID).OrderID,
                DateAdded = DateTime.Now,
                ClientID = rep.GetUser(WebSecurity.CurrentUserId).ClientID ?? 0
            };

            var order = rep.GetQuickBooksOrderByRequestID(requestID);
            order.ResponseXML = xmlMessage;
            rep.Add(failure);
            rep.Save();

            var hostUrl = HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
            hostUrl = "http://quickbooks.infomedia.com";
            var importUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/Unprocessed-Invoices");
            var modifyUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/Inventory");
            var body = new System.Text.StringBuilder();
            body.AppendLine("There was an error processing a website sale with Quickbooks");
            body.AppendLine("The most likely cause was that an item on the order was not found in your quickbooks inventory.");
            body.AppendLine("Please view the order that failed and create the invoice manually here: " + importUrl);
            body.AppendLine("You can modify your inventory naming schema here: " + modifyUrl);
            body.AppendLine(order.Receipt);
            body.AppendLine(xmlMessage);
            var user = rep.GetUser(WebSecurity.CurrentUserId);
            var email = user.Client.EmailRecipient != null ? user.Client.EmailRecipient : WebSecurity.CurrentUserName;
            WebMail.Send(email, "Quickbooks Web Connector Failed Invoice Attempt", body.ToString(), cc: "*****@*****.**", isBodyHtml: false);
        }
コード例 #2
0
ファイル: ProcessQueryRs.cs プロジェクト: krisburtoft/QBWC
 public static void InventoryQuery(string response)
 {
     var rep = new Repository();
     var doc = XDocument.Parse(response);
     var itemInventoryQueryRs = doc.Document.Root.Descendants("QBXMLMsgsRs").FirstOrDefault().Descendants("ItemInventoryQueryRs").FirstOrDefault();
     var msg = itemInventoryQueryRs.Attribute("statusMessage").Value;
     var requestID = Convert.ToInt32(itemInventoryQueryRs.Attribute("requestID").Value);
     if (msg == "A query request did not find a matching object in QuickBooks")
     {
         Error.ProcessFailedOrder(requestID,response);
     }
     else
     {
         var order = rep.GetQuickBooksOrderByRequestID(requestID);
         var quickbooksItem = new QuickbooksInventory(){
             ClientID = order.ClientID,
             FullName = itemInventoryQueryRs.Element("ItemInventoryRet").Element("FullName").Value,
             ListID = itemInventoryQueryRs.Element("ItemInventoryRet").Element("ListID").Value,
         };
         rep.Add(quickbooksItem);
         rep.Save();
         var shopInventory = rep.GetShopInventoryItems(order.ClientID).Where(i => i.Name == itemInventoryQueryRs.Element("ItemInventoryRet").Element("FullName").Value).SingleOrDefault();
         if (shopInventory == null)
         {
             rep.Add(new ShopInventory(){
                  ClientID = order.ClientID,
                  Name = itemInventoryQueryRs.Element("ItemInventoryRet").Element("FullName").Value,
                  QuickbooksInventoryID = quickbooksItem.QuickbooksInventoryID
             });
         }
         else
         {
             shopInventory.QuickbooksInventoryID = quickbooksItem.QuickbooksInventoryID;
         }
         order.Reported = false;
         rep.Save();
     }
 }