Exemple #1
0
        public ActionResult SyncPOR(string PORs, string ItemType = "NonInventory", int count = 1)
        {
            try
            {
                qbModels = new QBModels();
                int   siteCoID = base.siteusercompanyid;
                int[] PORS     = Array.ConvertAll(PORs.Remove(PORs.Length - 1, 1).Split(','), s => int.Parse(s));
                foreach (int PORid in PORS)
                {
                    QBAuthorizationdto oAuthDetails = new QBOAuthService(new QBAuthorizationdto()).GetAccessToken(this);
                    syncService            = new QBSyncService(oAuthDetails);
                    syncObjects            = new QBSyncdto();
                    syncObjects.OauthToken = oAuthDetails;
                    syncObjects.CompanyId  = oAuthDetails.Realmid;
                    syncObjects            = syncService.SyncPorder(syncObjects, siteCoID, PORid, ItemType);
                }
                TempData["SyncSuccessMessage"] = "Synchronization Process Completed";

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                if (count < 5)
                {
                    return(Redirect("SyncPOR?PORs=" + PORs + "&ItemType=" + ItemType + "&count=" + (count + 1)));
                }
                else
                {
                    //throw;
                    TempData["SyncErrorMessage"] = ex.Message;
                    return(RedirectToAction("Index"));
                }
            }
        }
        public ActionResult SyncSO(int SOID, string EstInvType, string ItemType = "NonInventory", int count = 1)
        {
            try
            {
                qbModels = new QBModels();
                int siteCoID = base.siteusercompanyid;
                if (SOID != 0)
                {
                    QBAuthorizationdto oAuthDetails = new QBOAuthService(new QBAuthorizationdto()).GetAccessToken(this);
                    syncService            = new QBSyncService(oAuthDetails);
                    syncObjects            = new QBSyncdto();
                    syncObjects.OauthToken = oAuthDetails;
                    syncObjects.CompanyId  = oAuthDetails.Realmid;
                    syncObjects            = syncService.SyncSalesOrder(syncObjects, siteCoID, SOID, EstInvType, ItemType);
                }
                TempData["SyncSuccessMessage"] = "Synchronization Process Completed";

                return(RedirectToAction("details", new { id = SOID }));
            }
            catch (Exception ex)
            {
                if (count < 5)
                {
                    return(Redirect("SyncSO?SOID=" + SOID + "&EstInvType=" + EstInvType + "&ItemType=" + ItemType + "&count=" + (count + 1)));
                }
                else
                {
                    //throw;
                    TempData["SyncErrorMessage"] = ex.Message;
                    return(RedirectToAction("details", new { id = SOID }));
                }
            }
        }
Exemple #3
0
        internal QBSyncdto Save(object controller, QBSyncdto syncObjects)
        {
            integrationsOptionsController = controller as Controller;
            Random random = new Random();

            syncObjects.Id = random.Next(1, 100);
            syncRepo.Add(syncObjects.Id, syncObjects);
            integrationsOptionsController.TempData["Sync"] = syncRepo;
            integrationsOptionsController.TempData.Keep();
            return(syncObjects);
        }
        public ActionResult SyncSingleJob(int?id, string nav)
        {
            QBAuthorizationdto oAuthDetails = new QBOAuthService(new QBAuthorizationdto()).GetAccessToken(this);

            syncService            = new QBSyncService(oAuthDetails);
            syncObjects            = new QBSyncdto();
            syncObjects.OauthToken = oAuthDetails;
            syncObjects.CompanyId  = oAuthDetails.Realmid;
            int parentid = 0;

            syncObjects = syncService.GetDatafromModelJobs(syncObjects, siteusercompanyid, Convert.ToInt32(id), out parentid);
            if (syncObjects.CustomerList.Count > 0)
            {
                syncObjects = syncService.SyncJob(this, syncObjects, (int)id, parentid, siteusercompanyid);
            }
            return(RedirectToAction("details", new { id = id, nav = nav }));
        }
        public ActionResult SyncToQBItems(int?id, string type)
        {
            int   siteCoID = base.siteusercompanyid;
            Int64 id1      = SyncObjectsModelId;
            QBAuthorizationdto oAuthDetails = new QBOAuthService(new QBAuthorizationdto()).GetAccessToken(this);

            syncService            = new QBSyncService(oAuthDetails);
            syncObjects            = id1 > 0 ? GetSyncObjects(this, id1) : new QBSyncdto();
            syncObjects.OauthToken = oAuthDetails;
            syncObjects.CompanyId  = oAuthDetails.Realmid;
            syncObjects            = syncService.GetDatafromModelItems(syncObjects, siteCoID, id, type);
            if (syncObjects.ItemList.Count > 0)
            {
                syncObjects = syncService.SyncItems(this, syncObjects);
            }
            this.Save(this, syncObjects);

            return(RedirectToAction("details", new { id = id }));
        }
Exemple #6
0
        public ActionResult CreateCustomer(PeopleModels.NewContact Model)
        {
            Int64 id = SyncObjectsModelId;
            QBAuthorizationdto oAuthDetails = new QBOAuthService(new QBAuthorizationdto()).GetAccessToken(this);

            syncService            = new QBSyncService(oAuthDetails);
            syncObjects            = id > 0 ? GetSyncObjects(this, id) : new QBSyncdto();
            syncObjects.OauthToken = oAuthDetails;
            syncObjects.CompanyId  = oAuthDetails.Realmid;

            if (!syncService.IsCustSync(syncObjects, syncService, siteusercompanyid).IsCustomerSync)
            {
                syncObjects = syncService.GetDatafromModelCustomer(syncObjects, siteusercompanyid);
                if (syncObjects.CustomerList.Count > 0)
                {
                    syncObjects = syncService.SyncCustomer(this, syncObjects);
                }
                this.Save(this, syncObjects);
            }
            return(RedirectToAction("Details", "contactinfo", new { id = Model.ContactID, area = "pages" }));
        }
Exemple #7
0
        public ActionResult Index(int?TypeID, long id)
        {
            ViewBag.ContactType = new SelectList(db.CoContactTypes.Where(p => p.SiteCoID == siteusercompanyid).OrderBy(p => p.ContactTypeOrder), "ContactTypeID", "ContactTypeName");
            string type = db.CoContactTypes.Where(p => p.ContactTypeID == TypeID).Select(p => p.ContactTypeName).FirstOrDefault();

            try
            {
                QBAuthorizationdto oAuthDetails = new QBOAuthService(new QBAuthorizationdto()).GetAccessToken(this);
                if (type.ToUpper() == "VENDOR")
                {
                    var dbvendorList = db.GetQbVendorsBySiteCoID(base.siteusercompanyid).ToList();
                    syncService            = new QBSyncService(oAuthDetails);
                    syncObjects            = id > 0 ? GetSyncObjects(this, id) : new QBSyncdto();
                    syncObjects.OauthToken = oAuthDetails;
                    syncObjects.CompanyId  = oAuthDetails.Realmid;
                    syncObjects            = syncService.GetVendorsFromQB(this, syncObjects);
                    if (syncObjects.VendorList.Count() > 0)
                    {
                        foreach (var q in syncObjects.VendorList.ToList())
                        {
                            var existingvendor = dbvendorList.Where(p => p.Id == q.Id && p.FamilyName == q.FamilyName && p.GivenName == q.GivenName).FirstOrDefault();
                            if (existingvendor == null)
                            {
                                var exsitingfamilyname = dbvendorList.Where(p => p.FamilyName == q.FamilyName).FirstOrDefault();
                                if (exsitingfamilyname != null)
                                {
                                    var exsitinggivingname = dbvendorList.Where(p => p.GivenName == q.GivenName).FirstOrDefault();
                                    if (exsitinggivingname == null)
                                    {
                                        var contacts  = GetDataForVendor(q, (int)TypeID);
                                        int contactid = SaveContact(contacts, q.Id);
                                    }
                                }
                                else
                                {
                                    var contacts  = GetDataForVendor(q, (int)TypeID);
                                    int contactid = SaveContact(contacts, q.Id);
                                }
                            }
                        }
                    }
                    if (!syncService.IsVendorSync(syncObjects, syncService, siteusercompanyid).IsVendorSync)
                    {
                        syncObjects = syncService.GetDatafromDBVendor(syncObjects, siteusercompanyid);
                        if (syncObjects.VendorList.Count > 0)
                        {
                            syncObjects = syncService.SyncVendor(this, syncObjects);
                        }
                        this.Save(this, syncObjects);
                    }
                    TempData["SyncSuccessMessage"] = "Synchronization Process Completed";
                }
                else if (type.ToUpper() == "CUSTOMER")
                {
                    var dbcustomerList = db.GetQbCustomersBySiteCoID(base.siteusercompanyid).ToList();
                    syncService            = new QBSyncService(oAuthDetails);
                    syncObjects            = id > 0 ? GetSyncObjects(this, id) : new QBSyncdto();
                    syncObjects.OauthToken = oAuthDetails;
                    syncObjects.CompanyId  = oAuthDetails.Realmid;
                    syncObjects            = syncService.GetCustomersFromQB(this, syncObjects);
                    if (syncObjects.CustomerList.Count() > 0)
                    {
                        foreach (var q in syncObjects.CustomerList.ToList())
                        {
                            var existingcustomer = dbcustomerList.Where(p => p.Id == q.Id).FirstOrDefault();
                            if (existingcustomer == null)
                            {
                                var exsitingfamilyname = dbcustomerList.Where(p => p.FamilyName == q.FamilyName).FirstOrDefault();
                                if (exsitingfamilyname != null)
                                {
                                    var exsitinggivingname = dbcustomerList.Where(p => p.GivenName == q.GivenName).FirstOrDefault();
                                    if (exsitinggivingname == null)
                                    {
                                        var contacts  = GetDataForCustomers(q, (int)TypeID);
                                        int contactid = SaveContact(contacts, q.Id);
                                    }
                                }
                                else
                                {
                                    var contacts  = GetDataForCustomers(q, (int)TypeID);
                                    int contactid = SaveContact(contacts, q.Id);
                                }
                            }
                        }
                    }
                    if (!syncService.IsCustSync(syncObjects, syncService, siteusercompanyid).IsCustomerSync)
                    {
                        syncObjects = syncService.GetDatafromDBCustomer(syncObjects, siteusercompanyid);
                        if (syncObjects.CustomerList.Count > 0)
                        {
                            syncObjects = syncService.SyncCustomer(this, syncObjects);
                        }
                        this.Save(this, syncObjects);
                    }
                    TempData["SyncSuccessMessage"] = "Synchronization Process Completed";
                }
                return(RedirectToAction("Index", "IntegrationsOptions", new { id = syncObjects.Id, isConnected = oAuthDetails.IsConnected }));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "IntegrationsOptions"));
                //throw ex;
            }
        }
Exemple #8
0
 private string SyncSingleCustomer(string type, int contactID)
 {
     if (type.ToUpper() == "CUSTOMER")
     {
         List <Intuit.Ipp.Data.Customer> custList = new List <Intuit.Ipp.Data.Customer>();
         var coContacts = db.GetQbCustomersBySiteCoID(siteusercompanyid).Where(x => x.ViewID == contactID).ToList();
         foreach (var cust in coContacts)
         {
             Intuit.Ipp.Data.Customer qboCust = new Intuit.Ipp.Data.Customer();
             qboCust.SyncToken = "1";
             if (cust.Id != null && cust.Id != "")
             {
                 qboCust.Id = cust.Id.ToString();
             }
             qboCust.GivenName = cust.GivenName;
             if (cust.FamilyName != null && cust.FamilyName != "")
             {
                 qboCust.FamilyName = cust.FamilyName;
             }
             if (cust.DisplayName != null && cust.DisplayName != "")
             {
                 qboCust.DisplayName = cust.DisplayName;
             }
             if (cust.CompanyName != null && cust.CompanyName != "")
             {
                 if (cust.CompanyName.Contains("'"))
                 {
                     cust.CompanyName = cust.CompanyName.Replace("'", "\'");
                 }
                 qboCust.CompanyName = cust.CompanyName;
             }
             if (cust.PrimaryPhone != null && cust.PrimaryPhone != "")
             {
                 qboCust.PrimaryPhone = new Intuit.Ipp.Data.TelephoneNumber {
                     FreeFormNumber = cust.PrimaryPhone.ToString()
                 }
             }
             ;
             if (cust.Mobile != null && cust.Mobile != "")
             {
                 qboCust.Mobile = new Intuit.Ipp.Data.TelephoneNumber {
                     FreeFormNumber = cust.Mobile.ToString()
                 }
             }
             ;
             if (cust.PrimaryEmailAddr != null && cust.PrimaryEmailAddr != "")
             {
                 qboCust.PrimaryEmailAddr = new Intuit.Ipp.Data.EmailAddress {
                     Address = cust.PrimaryEmailAddr.ToString()
                 }
             }
             ;
             qboCust.BillAddr = new Intuit.Ipp.Data.PhysicalAddress();
             if (cust.BillAddrId != 0)
             {
                 qboCust.BillAddr.Id = Convert.ToString(cust.BillAddrId);
             }
             if (cust.BillAddrLine1 != null && cust.BillAddrLine1 != "")
             {
                 qboCust.BillAddr.Line1 = cust.BillAddrLine1;
             }
             if (cust.BillAddrLine2 != null && cust.BillAddrLine2 != "")
             {
                 qboCust.BillAddr.Line2 = cust.BillAddrLine2;
             }
             if (cust.BillAddrCity != null && cust.BillAddrCity != "")
             {
                 qboCust.BillAddr.City = cust.BillAddrCity;
             }
             if (cust.BillAddrCountry != null && cust.BillAddrCountry != "")
             {
                 qboCust.BillAddr.Country = cust.BillAddrCountry;
             }
             if (cust.BillAddrCountrySubDivisionCode != null && cust.BillAddrCountrySubDivisionCode != "")
             {
                 qboCust.BillAddr.CountrySubDivisionCode = cust.BillAddrCountrySubDivisionCode;
             }
             if (cust.BillAddrPostalCode != null && cust.BillAddrPostalCode != "")
             {
                 qboCust.BillAddr.PostalCode = cust.BillAddrPostalCode;
             }
             if (cust.BillAddrLine1 != null && cust.BillAddrLine1 != "")
             {
                 qboCust.BillAddr.Line1 = cust.BillAddrLine1;
             }
             custList.Add(qboCust);
         }
         QBAuthorizationdto oAuthDetails = new QBOAuthService(new QBAuthorizationdto()).GetAccessToken(this);
         syncService              = new QBSyncService(oAuthDetails);
         syncObjects              = new QBSyncdto();
         syncObjects.OauthToken   = oAuthDetails;
         syncObjects.CompanyId    = oAuthDetails.Realmid;
         syncObjects.CustomerList = custList;
         if (syncObjects.CustomerList.Count > 0)
         {
             syncObjects = syncService.SyncCustomer(this, syncObjects);
         }
     }
     else if (type.ToUpper() == "VENDOR")
     {
         List <Intuit.Ipp.Data.Vendor> vendorList = new List <Intuit.Ipp.Data.Vendor>();
         var vendor = db.GetQbVendorsBySiteCoID(siteusercompanyid).Where(p => p.ViewID == contactID).FirstOrDefault();
         if (vendor != null)
         {
             Intuit.Ipp.Data.Vendor qboVendor = new Intuit.Ipp.Data.Vendor();
             qboVendor.SyncToken = "1";
             qboVendor.GivenName = vendor.GivenName;
             if (vendor.FamilyName != null && vendor.FamilyName != "")
             {
                 qboVendor.FamilyName = vendor.FamilyName;
             }
             if (vendor.DisplayName != null && vendor.DisplayName != "")
             {
                 qboVendor.DisplayName = vendor.DisplayName;
             }
             if (vendor.CompanyName != null && vendor.CompanyName != "")
             {
                 qboVendor.CompanyName = vendor.CompanyName;
             }
             if (vendor.PrimaryPhone != null && vendor.PrimaryPhone != "")
             {
                 qboVendor.PrimaryPhone = new Intuit.Ipp.Data.TelephoneNumber {
                     FreeFormNumber = vendor.PrimaryPhone.ToString()
                 }
             }
             ;
             if (vendor.Mobile != null && vendor.Mobile != "")
             {
                 qboVendor.Mobile = new Intuit.Ipp.Data.TelephoneNumber {
                     FreeFormNumber = vendor.Mobile.ToString()
                 }
             }
             ;
             if (vendor.PrimaryEmailAddr != null && vendor.PrimaryEmailAddr != "")
             {
                 qboVendor.PrimaryEmailAddr = new Intuit.Ipp.Data.EmailAddress {
                     Address = vendor.PrimaryEmailAddr.ToString()
                 }
             }
             ;
             qboVendor.BillAddr = new Intuit.Ipp.Data.PhysicalAddress();
             if (vendor.BillAddrId != 0)
             {
                 qboVendor.BillAddr.Id = Convert.ToString(vendor.BillAddrId);
             }
             if (vendor.BillAddrLine1 != null && vendor.BillAddrLine1 != "")
             {
                 qboVendor.BillAddr.Line1 = vendor.BillAddrLine1;
             }
             if (vendor.BillAddrLine2 != null && vendor.BillAddrLine2 != "")
             {
                 qboVendor.BillAddr.Line2 = vendor.BillAddrLine2;
             }
             if (vendor.BillAddrCity != null && vendor.BillAddrCity != "")
             {
                 qboVendor.BillAddr.City = vendor.BillAddrCity;
             }
             if (vendor.BillAddrCountry != null && vendor.BillAddrCountry != "")
             {
                 qboVendor.BillAddr.Country = vendor.BillAddrCountry;
             }
             if (vendor.BillAddrCountrySubDivisionCode != null && vendor.BillAddrCountrySubDivisionCode != "")
             {
                 qboVendor.BillAddr.CountrySubDivisionCode = vendor.BillAddrCountrySubDivisionCode;
             }
             if (vendor.BillAddrPostalCode != null && vendor.BillAddrPostalCode != "")
             {
                 qboVendor.BillAddr.PostalCode = vendor.BillAddrPostalCode;
             }
             if (vendor.BillAddrLine1 != null && vendor.BillAddrLine1 != "")
             {
                 qboVendor.BillAddr.Line1 = vendor.BillAddrLine1;
             }
             vendorList.Add(qboVendor);
         }
         QBAuthorizationdto oAuthDetails = new QBOAuthService(new QBAuthorizationdto()).GetAccessToken(this);
         syncService            = new QBSyncService(oAuthDetails);
         syncObjects            = new QBSyncdto();
         syncObjects.OauthToken = oAuthDetails;
         syncObjects.CompanyId  = oAuthDetails.Realmid;
         syncObjects.VendorList = vendorList;
         if (syncObjects.VendorList.Count > 0)
         {
             syncObjects = syncService.SyncVendor(this, syncObjects);
         }
     }
     return("");
 }