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 }));
                }
            }
        }
Exemplo n.º 2
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 Create()
        {
            qbModels = new QBModels();
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteusercompanyid);

            ViewBag.IsQBConnected = "false";
            if (oAuthModel.IsConnected)
            {
                ViewBag.IsConnected = "true";
                //qbModels.IsReadySync = true;
                //qbModels.OAuthorizationModel = oAuthModel;
                //qbModels.IsConnected = oAuthModel.IsConnected;
                //var syncService = new QBSyncService(oAuthModel);
                //qbModels.SyncObjectsModel.OauthToken = oAuthModel;
                //Random random = new Random();
                //SyncObjectsModelId = random.Next(1, 100);
                //ViewBag.IsQBConnected = "true";
                //SyncObjectsModelId = qbModels.SyncObjectsModel.Id;
            }
            ViewBag.Group        = new SelectList(db.GetGroupsBySiteCoID(base.siteusercompanyid).ToList(), nameof(GetGroupsBySiteCoID_Result.ViewID), nameof(GetGroupsBySiteCoID_Result.Group));
            ViewBag.Manufacturer = new SelectList(db.GetManufacturersBySiteCoID(base.siteusercompanyid).ToList(), nameof(GetManufacturersBySiteCoID_Result.ViewID), nameof(GetManufacturersBySiteCoID_Result.Name));
            return(View());
        }
        public ActionResult Details(int?id) //SOID
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var soInfo = db.GetSoInfoBySoID(id).FirstOrDefault();
            var so     = db.ProjectSOs.Where(p => p.SoID == id).FirstOrDefault();

            if (soInfo == null || so == null)
            {
                return(HttpNotFound());
            }
            if (TempData["SyncSuccessMessage"] != null)
            {
                ViewBag.SyncSuccessMessage = TempData["SyncSuccessMessage"];
                TempData.Remove("SyncSuccessMessage");
            }
            if (TempData["SyncErrorMessage"] != null)
            {
                ViewBag.SyncErrorMessage = TempData["SyncErrorMessage"];
                TempData.Remove("SyncErrorMessage");
            }
            ViewBag.Parts = db.GetSoInfoPartsBySoID(id).ToList();

            ViewBag.ProjectID            = so.ProjectID;
            ViewBag.IsApproved           = so.Approved;
            qbModels                     = new QBModels();
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteusercompanyid);

            if (oAuthModel.IsConnected)
            {
                ViewBag.IsQBConnected = true;
            }
            if (string.IsNullOrEmpty(so.AcctSoID))
            {
                ViewBag.IsNotSynced = true;
            }

            return(View(soInfo));
        }
        public ActionResult Create(int?contactid, int?quoteid, string from)
        {
            var siteCoID  = siteusercompanyid;
            var siteUsers = db.GetSiteUsersBySiteCoID(siteCoID).ToList();

            ViewBag.Clients       = new SelectList(db.GetContactsBySiteCoID(siteCoID).ToList(), "ViewID", "Customer", contactid);
            ViewBag.ProjectStatus = new SelectList(db.GetJobStatusBySiteCoID(siteCoID), "ViewID", "Name");
            ViewBag.SiteUsers     = new SelectList(siteUsers, "ViewID", "User");
            ViewBag.Builders      = new SelectList(db.GetBuildersBySiteCoID(siteCoID).ToList(), "ViewID", "Builder", contactid);
            qbModels = new QBModels();
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteusercompanyid);

            ViewBag.IsQBConnected = "false";
            if (oAuthModel.IsConnected)
            {
                ViewBag.IsQBConnected = "true";
            }
            LoadAdditionalDropdownData();
            JobModels.NewJob model = new JobModels.NewJob();
            var newJobId           = 0;

            if (quoteid.HasValue)
            {
                newJobId = repo.CopyQuoteTojob(quoteid.Value);
                model    = LoadProjectInfo(newJobId);
            }
            else
            {
                newJobId               = repo.GenerateNewProjectID();
                model.SalesPersonID    = siteuserid;
                model.ProjectManagerID = siteuserid;
                model.DesignerID       = siteuserid;
            }

            model.JobID     = newJobId;
            model.Date      = DateTime.Now;
            model.JobNumber = db.GetNewJobNumFormat(siteusercompanyid).FirstOrDefault();
            return(View(model));
        }
Exemplo n.º 6
0
        // GET: Sections/Procurement
        public ActionResult Index()
        {
            int siteCoID = base.siteusercompanyid;

            if (TempData["SyncSuccessMessage"] != null)
            {
                ViewBag.SyncSuccessMessage = TempData["SyncSuccessMessage"];
                TempData.Remove("SyncSuccessMessage");
            }
            if (TempData["SyncErrorMessage"] != null)
            {
                ViewBag.SyncErrorMessage = TempData["SyncErrorMessage"];
                TempData.Remove("SyncErrorMessage");
            }
            ViewBag.VendorList    = db.GetVendorsByPors(siteusercompanyid).Where(s => s.Vendor != null && s.Vendor.Trim() != "").ToList();
            ViewBag.JobList       = db.GetProjectsByPors(siteusercompanyid).ToList();
            ViewBag.StatusList    = db.GetStatusByPors(siteusercompanyid).ToList();
            ViewBag.SelectPORList = db.GetPorNumberByPors(siteCoID).ToList();

            ProcurementResult result = new ProcurementResult();

            result.PurchaseList          = db.GetPurchasingBySiteCoID(siteCoID).ToList();
            result.CustodyList           = db.GetCustodyBySiteCoID(siteCoID).ToList();
            result.DeliveryList          = db.GetDeliveriesBySiteCoID(siteCoID).ToList();
            result.TransferList          = db.GetTransfersBySiteCoID(siteCoID).ToList();
            result.PendingList           = db.GetPendingBySiteCoID(siteCoID).ToList();
            result.InventoryList         = db.GetInventoryBySiteCoID(siteCoID).ToList();
            qbModels                     = new QBModels();
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteusercompanyid);

            if (oAuthModel.IsConnected)
            {
                ViewBag.IsQBConnected = true;
            }
            return(View(result));
        }
Exemplo n.º 7
0
        // GET: Pages/ContactInfo/Create
        public ActionResult Create(int?contactid, int?contactTypeID)
        {
            var siteCoID = siteusercompanyid;

            ViewBag.ContactCo      = new SelectList(db.GetContactCompaniesBySiteCoID(siteCoID), "ViewID", "Company", siteCoID);
            ViewBag.Country        = new SelectList(new CommonRepository().GetCountries(), "CountryID", "Country");
            ViewBag.ContactType    = new SelectList(db.GetPeopleTypesBySiteCoID(siteCoID), "ViewID", "Name", siteCoID);
            ViewBag.ContactSubType = new SelectList(db.GetContactSubTypesBySiteCoID(siteCoID), "ViewID", "Type", siteCoID);
            ViewBag.ContactStatus  = new SelectList(db.SiteContactStatus.OrderBy(p => p.StatusOrder), "StatusID", "Status");
            ViewBag.Owner          = new SelectList(db.GetCoUsersBySiteCoID(siteCoID), "UserID", "User", siteCoID);
            ViewBag.ContactCustoms = db.GetContactCustomFieldsBySiteCoID(siteCoID).FirstOrDefault();
            ViewBag.siteuserid     = siteuserid;
            qbModels = new QBModels();
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteusercompanyid);

            ViewBag.IsQBConnected = "false";
            if (oAuthModel.IsConnected)
            {
                qbModels.IsReadySync         = true;
                qbModels.OAuthorizationModel = oAuthModel;
                qbModels.IsConnected         = oAuthModel.IsConnected;
                var syncService = new QBSyncService(oAuthModel);
                qbModels.SyncObjectsModel.OauthToken = oAuthModel;
                Random random = new Random();
                SyncObjectsModelId    = random.Next(1, 100);
                ViewBag.IsQBConnected = "true";
                //SyncObjectsModelId = qbModels.SyncObjectsModel.Id;
            }
            GetContactInfoByContactID_Result Model = new GetContactInfoByContactID_Result();

            Model.ViewID = 0;
            return(View(Model));
        }
Exemplo n.º 8
0
        public ActionResult Index(string SearchText, string SelectedType, string SelectedVendors, string SelectedJobs, string SelectedStatus = "", string SelectedPOR = "")
        {
            int siteCoID = base.siteusercompanyid;

            if (TempData["SyncSuccessMessage"] != null)
            {
                ViewBag.SyncSuccessMessage = TempData["SyncSuccessMessage"];
                TempData.Remove("SyncSuccessMessage");
            }
            if (TempData["SyncErrorMessage"] != null)
            {
                ViewBag.SyncErrorMessage = TempData["SyncErrorMessage"];
                TempData.Remove("SyncErrorMessage");
            }
            ViewBag.VendorList    = db.GetVendorsByPors(siteusercompanyid).Where(s => s.Vendor != null && s.Vendor.Trim() != "").ToList();
            ViewBag.JobList       = db.GetProjectsByPors(siteusercompanyid).ToList();
            ViewBag.StatusList    = db.GetStatusByPors(siteusercompanyid).ToList();
            ViewBag.SelectPORList = db.GetPorNumberByPors(siteCoID).ToList();

            ProcurementResult result = new ProcurementResult();
            var PurchaseList         = db.GetPurchasingBySiteCoID(siteCoID).ToList();

            if (SelectedType == "PO")
            {
                char[] sep = new char[] { ',' };
                if (SelectedVendors != null && SelectedVendors != "")
                {
                    PurchaseList = PurchaseList.Where(p => SelectedVendors.Split(sep).Contains(Convert.ToString(p.VendorID))).ToList();
                }
                if (SelectedJobs != null && SelectedJobs != "")
                {
                    PurchaseList = PurchaseList.Where(p => SelectedJobs.Split(sep).Contains(Convert.ToString(p.ProjectID))).ToList();
                }
                if (SelectedStatus != null && SelectedStatus != "")
                {
                    PurchaseList = PurchaseList.Where(p => SelectedStatus.Split(sep).Contains(Convert.ToString(p.StatusID))).ToList();
                }
            }
            var CustodyList = db.GetCustodyBySiteCoID(siteCoID).ToList();

            if (SelectedType == "Custody")
            {
                char[] sep = new char[] { ',' };
                if (SelectedVendors != null && SelectedVendors != "")
                {
                    CustodyList = CustodyList.Where(p => SelectedVendors.Split(sep).Contains(Convert.ToString(p.VendorID))).ToList();
                }
                if (SelectedJobs != null && SelectedJobs != "")
                {
                    CustodyList = CustodyList.Where(p => SelectedJobs.Split(sep).Contains(Convert.ToString(p.ProjectID))).ToList();
                }
                if (SelectedPOR != null && SelectedPOR != "")
                {
                    CustodyList = CustodyList.Where(p => SelectedPOR.Split(sep).Contains(Convert.ToString(p.PorID))).ToList();
                }
            }
            result.DeliveryList          = db.GetDeliveriesBySiteCoID(siteCoID).ToList();
            result.TransferList          = db.GetTransfersBySiteCoID(siteCoID).ToList();
            result.PendingList           = db.GetPendingBySiteCoID(siteCoID).ToList();
            result.InventoryList         = db.GetInventoryBySiteCoID(siteCoID).ToList();
            result.CustodyList           = CustodyList.ToList();
            result.PurchaseList          = PurchaseList.ToList();
            qbModels                     = new QBModels();
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteusercompanyid);

            if (oAuthModel.IsConnected)
            {
                ViewBag.IsQBConnected = true;
            }
            return(View(result));
        }
Exemplo n.º 9
0
        public ActionResult Index()
        {
            if (TempData["SyncSuccessMessage"] != null)
            {
                ViewBag.SyncSuccessMessage = TempData["SyncSuccessMessage"];
                TempData.Remove("SyncSuccessMessage");
            }
            sTService             = new STServices();
            ViewBag.IsDBConnected = false;
            ViewBag.IsQBConnected = false;
            ViewBag.IsSTConnected = sTService.IsConnected(siteuserid);

            CoDropbox drpconnection = db.CoDropbox.Where(p => p.SiteCoID == siteusercompanyid).FirstOrDefault();

            if (drpconnection != null)
            {
                ViewBag.IsDBConnected = true;
            }
            CoQuickBooks currentIndex = db.CoQuickBooks.Where(p => p.SiteCoID == siteusercompanyid).FirstOrDefault();

            if (currentIndex != null)
            {
                ViewBag.IsQBConnected = true;
            }
            ViewBag.ContactType = new SelectList(db.CoContactTypes.Where(p => p.SiteCoID == siteusercompanyid).OrderBy(p => p.ContactTypeOrder), "ContactTypeID", "ContactTypeName");
            int siteCoID   = base.siteusercompanyid;
            var coContacts = db.CoContacts
                             .Where(p => p.SiteCoID == siteCoID)
                             .Include(c => c.CoContactCompanies)
                             .Include(p => p.CoContactPhones)
                             .Include(p => p.CoContactEmails)
                             //.Include(c => c.CoContactSubtypes)
                             .Include(c => c.CoContactTypes)
                             .Include(c => c.SiteContactStatus)
                             .OrderBy(p => p.ContactLastName).ThenBy(p => p.ContactFirstName).ThenBy(p => p.CoContactCompanies.ContactCoName);

            qbModels                     = new QBModels();
            qbModels.coContacts          = coContacts.ToList();
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteCoID);

            if (oAuthModel.IsConnected)
            {
                qbModels.IsReadySync         = true;
                qbModels.OAuthorizationModel = oAuthModel;
                qbModels.IsConnected         = oAuthModel.IsConnected;
                var syncService = new QBSyncService(oAuthModel);
                qbModels.SyncObjectsModel.OauthToken = oAuthModel;
                //    qbModels.SyncObjectsModel = syncService.IsCustSync(qbModels.SyncObjectsModel, syncService, siteusercompanyid);
                qbModels.SyncObjectsModel.CompanyId = oAuthModel.Realmid;
                qbModels.SyncObjectsModel           = Save(this, qbModels.SyncObjectsModel);
                qbModels.IsReadyTimeentry           = qbModels.SyncObjectsModel.IsCustomerSync;
                qbModels.IsReadytoInvoice           = false;
                return(View(qbModels));
            }
            else
            {
                return(View(qbModels));
            }
        }
        public ActionResult Details(int?id)
        {
            var data = db.GetItemInfoByMasterItemID(id).FirstOrDefault();

            if (data.Vendor != null)
            {
                ViewBag.Vendors = new SelectList(db.GetVendorsBySiteCoID(base.siteusercompanyid).ToList(), nameof(GetVendorsBySiteCoID_Result.ViewID), nameof(GetVendorsBySiteCoID_Result.Vendor), data.Vendor);
            }
            else
            {
                ViewBag.Vendors = new SelectList(db.GetVendorsBySiteCoID(base.siteusercompanyid).ToList(), nameof(GetVendorsBySiteCoID_Result.ViewID), nameof(GetVendorsBySiteCoID_Result.Vendor));
            }
            ViewBag.SalesUom  = new SelectList(db.GetSiteDataUom().ToList(), nameof(GetSiteDataUom_Result.ViewID), nameof(GetSiteDataUom_Result.Uom), data.SaleUom);
            ViewBag.OrderUom  = new SelectList(db.GetSiteDataUom().ToList(), nameof(GetSiteDataUom_Result.ViewID), nameof(GetSiteDataUom_Result.Uom), data.OrderUom);
            ViewBag.CostCodes = new SelectList(db.GetCoCostCodesBySiteCoID(siteusercompanyid).ToList(), nameof(GetCoCostCodesBySiteCoID_Result.CostCodeID), nameof(GetCoCostCodesBySiteCoID_Result.CostCode));
            var projectID = db.ProjectItems.Where(p => p.MasterItemID == id).Select(p => p.ProjectID).FirstOrDefault();

            ViewBag.CoStages = new SelectList(db.GetMasterStagesBySiteID(siteusercompanyid).ToList(), nameof(GetMasterStagesBySiteID_Result.ViewID), nameof(GetMasterStagesBySiteID_Result.Stage));
            var stage = db.GetStageMasterEditInfoByID(data.StageID).FirstOrDefault();

            if (stage != null)
            {
                var subLabors = db.GetSubLaborInfoByMasterItemID(id).ToList();
                var Labors    = new StageModels.StageMasterEdit();
                if (subLabors != null)
                {
                    foreach (var sub in subLabors)
                    {
                        Labors.StageSubDetails.Add(new StageModels.StageDetails()
                        {
                            StageMasterID = stage.StageMasterID,
                            SubStageID    = sub.SubID,
                            SubName       = sub.SubStage,
                            CostPerHour   = sub.Cost,
                            PricePerHour  = sub.Price,
                            Percent       = sub.Factor,
                            SellPerHour   = sub.Sell
                        });
                    }
                }
                ViewBag.Labors = Labors;
            }
            if (data == null)
            {
                return(HttpNotFound());
            }
            else
            {
                ViewBag.AcctItemID = data.AcctItemID;
            }
            int siteCoID = base.siteusercompanyid;

            qbModels = new QBModels();
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteusercompanyid);

            if (oAuthModel.IsConnected)
            {
                qbModels.IsReadySync         = true;
                qbModels.OAuthorizationModel = oAuthModel;
                qbModels.IsConnected         = oAuthModel.IsConnected;
                var syncService = new QBSyncService(oAuthModel);
                qbModels.SyncObjectsModel.OauthToken = oAuthModel;
                qbModels.SyncObjectsModel.CompanyId  = oAuthModel.Realmid;
                Random random = new Random();
                qbModels.SyncObjectsModel = Save(this, qbModels.SyncObjectsModel);
                SyncObjectsModelId        = qbModels.SyncObjectsModel.Id;
            }

            return(View(data));
        }
        public ActionResult GetContacts([DataSourceRequest] DataSourceRequest request, string LastName, string SelectedCompanies, string SelectedTypes, string SelectedSubTypes, bool?getall)
        {
            int siteCoID   = base.siteusercompanyid;
            var coContacts = db.CoContacts
                             .Where(p => p.SiteCoID == siteCoID)
                             .Include(c => c.CoContactCompanies)
                             .Include(p => p.CoContactPhones)
                             .Include(p => p.CoContactEmails)
                             //.Include(c => c.CoContactSubtypes)
                             .Include(c => c.CoContactTypes)
                             .Include(c => c.SiteContactStatus)
                             .OrderBy(p => p.ContactLastName).ThenBy(p => p.ContactFirstName).ThenBy(p => p.CoContactCompanies.ContactCoName);

            //var q = new List<CoContacts>();
            var q = coContacts.Where(p => p.ContactManager == siteuserid);

            if (getall == true)
            {
                q = coContacts;
            }
            if (LastName != null && LastName != "")
            {
                LastName = LastName.Trim().ToLower();
                q        = q.Where(p => (p.ContactLastName == null ? "" : p.ContactLastName).ToLower().Contains(LastName) || (p.ContactFirstName == null ? "" : p.ContactFirstName).ToLower().Contains(LastName));
            }
            char[] sep = new char[] { ',' };
            if (SelectedCompanies != null && SelectedCompanies.Trim() != "")
            {
                int[] str_arr;
                str_arr = SelectedCompanies.Split(',').Select <string, int>(int.Parse).ToArray();
                q       = q.Where(p => str_arr.Contains(p.ContactCoID.HasValue ? p.ContactCoID.Value : 0));
            }
            if (SelectedTypes != null && SelectedTypes.Trim() != "")
            {
                int[] str_arr;
                str_arr = SelectedTypes.Split(',').Select <string, int>(int.Parse).ToArray();
                q       = q.Where(p => str_arr.Contains(p.ContactTypeID));
            }
            if (SelectedSubTypes != null && SelectedSubTypes.Trim() != "")
            {
                int[] str_arr;
                str_arr = SelectedSubTypes.Split(',').Select <string, int>(int.Parse).ToArray();
                q       = q.Where(p => str_arr.Contains(p.ContactSubtypeID.HasValue ? p.ContactSubtypeID.Value : 0));
            }
            //if (Company != null && Company != 0)
            //    q = q.Where(p => p.ContactCoID == Company).ToList();
            //if (Type != null && Type != 0)
            //    q = q.Where(p => p.ContactTypeID == Type).ToList();

            //List<CoContacts> listcontact = q.Skip((currentpage - 1) * CommonCls.PageSize).Take(CommonCls.PageSize).ToList();
            List <CoContacts> listcontact = q.ToList();

            foreach (var item in listcontact)
            {
                if (item.CoContactCompanies == null)
                {
                    item.CoContactCompanies = new CoContactCompanies();
                }
                if (item.CoContactTypes == null)
                {
                    item.CoContactTypes = new CoContactTypes();
                }
                if (item.CoContactSubtypes == null)
                {
                    item.CoContactSubtypes = new CoContactSubtypes();
                }
            }


            qbModels                     = new QBModels();
            qbModels.coContacts          = listcontact;
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteCoID);

            if (oAuthModel.IsConnected)
            {
                qbModels.IsReadySync         = true;
                qbModels.OAuthorizationModel = oAuthModel;
                qbModels.IsConnected         = oAuthModel.IsConnected;
                var syncService = new QBSyncService(oAuthModel);
                qbModels.SyncObjectsModel.OauthToken = oAuthModel;
                //    qbModels.SyncObjectsModel = syncService.IsCustSync(qbModels.SyncObjectsModel, syncService, siteusercompanyid);
                qbModels.SyncObjectsModel.CompanyId = oAuthModel.Realmid;
                qbModels.SyncObjectsModel           = Save(this, qbModels.SyncObjectsModel);
                qbModels.IsReadyTimeentry           = qbModels.SyncObjectsModel.IsCustomerSync;
                qbModels.IsReadytoInvoice           = false;
                // return View(qbModels);


                List <ContactList> Contact = new List <ContactList>();

                foreach (var C in qbModels.coContacts)
                {
                    ContactList Contact1 = new ContactList();

                    Contact1.ContactID        = C.ContactID;
                    Contact1.ContactFirstName = C.ContactFirstName;
                    Contact1.ContactLastName  = C.ContactLastName;
                    Contact1.ContactCoName    = C.CoContactCompanies.ContactCoName;
                    Contact1.ContactTypeName  = C.CoContactTypes.ContactTypeName;
                    Contact1.SubtypeName      = C.CoContactSubtypes.SubtypeName;
                    Contact.Add(Contact1);
                }


                DataSourceResult result = Contact.ToDataSourceResult(request);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                List <ContactList> Contact = new List <ContactList>();

                foreach (var C in qbModels.coContacts)
                {
                    ContactList Contact1 = new ContactList();
                    Contact1.ContactID        = C.ContactID;
                    Contact1.ContactFirstName = C.ContactFirstName;
                    Contact1.ContactLastName  = C.ContactLastName;
                    Contact1.ContactCoName    = C.CoContactCompanies.ContactCoName;
                    Contact1.ContactTypeName  = C.CoContactTypes.ContactTypeName;
                    Contact1.SubtypeName      = C.CoContactSubtypes.SubtypeName;
                    Contact.Add(Contact1);
                }

                DataSourceResult result = Contact.ToDataSourceResult(request);
                return(Json(result, JsonRequestBehavior.AllowGet));
                //return View(qbModels);
            }
        }
        // GET: Sections/People
        public ActionResult Index()
        {
            //ViewBag.Sorting = new string[] { "Last", "First", "Company" };
            //ViewBag.Company=new SelectList(db.GetContactCompaniesBySiteCoID(siteusercompanyid).ToList(),nameof(GetContactCompaniesBySiteCoID_Result.ViewID), nameof(GetContactCompaniesBySiteCoID_Result.Company));
            ViewBag.CompanyList = db.GetContactCompaniesBySiteCoID(siteusercompanyid).Where(s => s.Company != null && s.Company.Trim() != "").ToList();
            //ViewBag.ContactType = new SelectList(db.CoContactTypes.Where(p => p.SiteCoID == siteusercompanyid).OrderBy(p => p.ContactTypeOrder), "ContactTypeID", "ContactTypeName");
            ViewBag.ContactTypeList = db.CoContactTypes.Where(p => p.SiteCoID == siteusercompanyid).OrderBy(p => p.ContactTypeOrder).ToList();
            int siteCoID = base.siteusercompanyid;
            //var coContacts = db.CoContacts
            //    .Where(p => p.SiteCoID == siteCoID)
            //    .Include(c => c.CoContactCompanies)
            //    .Include(p=>p.CoContactPhones)
            //    .Include(p=>p.CoContactEmails)
            //    //.Include(c => c.CoContactSubtypes)
            //    .Include(c => c.CoContactTypes)
            //    .Include(c => c.SiteContactStatus)
            //    .OrderBy(p => p.ContactLastName).ThenBy(p => p.ContactFirstName).ThenBy(p=>p.CoContactCompanies.ContactCoName);
            CoQuickBooks cqb = db.CoQuickBooks.Where(p => p.SiteCoID == siteusercompanyid).FirstOrDefault();

            if (cqb != null)
            {
                ViewBag.IsConnected = true;
            }
            qbModels = new QBModels();
            //var q = coContacts.Where(p => p.ContactManager == siteuserid);
            // ViewBag.TotalRecords = q.Count();
            //ViewBag.CurrentPage = 1;
            // ViewBag.CurrentSort = "Last";
            // ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(ViewBag.TotalRecords) / Convert.ToDouble(CommonCls.PageSize));
            //  List<CoContacts> listcontact = q.OrderBy(s=>s.ContactLastName).ToList();


            //foreach (var item in listcontact)
            //{
            //    if (item.CoContactCompanies == null)
            //    {
            //        item.CoContactCompanies = new CoContactCompanies();
            //    }
            //    if (item.CoContactTypes == null)
            //    {
            //        item.CoContactTypes = new CoContactTypes();
            //    }
            //    if (item.CoContactSubtypes == null)
            //    {
            //        item.CoContactSubtypes = new CoContactSubtypes();
            //    }



            //}
            //List<ContactList> Contact = new List<ContactList>();
            //Int64 Id = 0;
            //foreach (var C in listcontact)
            //{
            //    Id++;
            //    ContactList Contact1 = new ContactList();
            //    Contact1.Id = Id;
            //    Contact1.ContactFirstName = C.ContactFirstName;
            //    Contact1.ContactLastName = C.ContactLastName;
            //    Contact1.ContactCoName = C.CoContactCompanies.ContactCoName;
            //    Contact1.ContactTypeName = C.CoContactTypes.ContactTypeName;
            //    Contact1.SubtypeName = C.CoContactSubtypes.SubtypeName;
            //    Contact.Add(Contact1);
            //}

            //ViewBag.ContactsList = Contact;

            //qbModels.coContacts = listcontact;//coContacts.Where(p=>p.ContactManager==siteuserid).ToList().ForEach(s=>s.CoContactCompanies==null ? s.CoContactCompanies = new CoContactCompanies() : s.CoContactCompanies = s.CoContactCompanies);
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteCoID);

            if (oAuthModel.IsConnected)
            {
                qbModels.IsReadySync         = true;
                qbModels.OAuthorizationModel = oAuthModel;
                qbModels.IsConnected         = oAuthModel.IsConnected;
                var syncService = new QBSyncService(oAuthModel);
                qbModels.SyncObjectsModel.OauthToken = oAuthModel;
                //    qbModels.SyncObjectsModel = syncService.IsCustSync(qbModels.SyncObjectsModel, syncService, siteusercompanyid);
                qbModels.SyncObjectsModel.CompanyId = oAuthModel.Realmid;
                qbModels.SyncObjectsModel           = Save(this, qbModels.SyncObjectsModel);
                qbModels.IsReadyTimeentry           = qbModels.SyncObjectsModel.IsCustomerSync;
                qbModels.IsReadytoInvoice           = false;

                return(View(qbModels));
            }
            else
            {
                return(View(qbModels));
            }
        }