/// <summary> /// Intitalise multiple models and kick start oauth/sync /// </summary> /// <returns></returns> public ActionResult Index() { multiplemodels = new Multiplemodels(); multiplemodels.SyncObjectsModel = new Syncdto(); multiplemodels.OAuthorizationModel = new OAuthorizationdto(); multiplemodels.TimeActivityModel = new TimeActivitydto(); multiplemodels.IsReadySync = false; var oAuthModel = new OAuthService(multiplemodels.OAuthorizationModel).IsTokenAvailable(this); if (oAuthModel.IsConnected) { multiplemodels.IsReadySync = true; multiplemodels.OAuthorizationModel = oAuthModel; multiplemodels.IsConnected = oAuthModel.IsConnected; var syncService = new SyncService(oAuthModel); multiplemodels.SyncObjectsModel.OauthToken = oAuthModel; multiplemodels.SyncObjectsModel = syncService.IsEmpSync(multiplemodels.SyncObjectsModel, syncService); multiplemodels.SyncObjectsModel = syncService.IsCustSync(multiplemodels.SyncObjectsModel, syncService); multiplemodels.SyncObjectsModel = syncService.IsServiceItemSync(multiplemodels.SyncObjectsModel, syncService); multiplemodels.SyncObjectsModel.CompanyId = oAuthModel.Realmid; multiplemodels.SyncObjectsModel = syncRepo.Save(this, multiplemodels.SyncObjectsModel); multiplemodels.IsReadyTimeentry = multiplemodels.SyncObjectsModel.IsEmployeeSync || multiplemodels.SyncObjectsModel.IsCustomerSync || multiplemodels.SyncObjectsModel.IsServiceItemSync; multiplemodels.IsReadytoInvoice = false; return(View(multiplemodels)); } else { return(View(multiplemodels)); } }
// #region <<Sync>> /// <summary> /// Sync the employees in to QBO. /// </summary> /// <param name="controller"></param> /// <param name="syncObjects"></param> /// <returns></returns> public Syncdto SyncEmployees(object controller, Syncdto syncObjects) { try { for (int i = 0; i < syncObjects.EmployeeList.Count; i++) { string EXISTING_EMPLOYEE_QUERY = string.Format("select * from employee where active = true and givenName = '{0}' and familyName = '{1}'", syncObjects.EmployeeList[i].GivenName.Trim(), syncObjects.EmployeeList[i].FamilyName.Trim()); QueryService <Employee> queryService = new QueryService <Employee>(dataserviceFactory.getServiceContext); Employee resultFound = queryService.ExecuteIdsQuery(EXISTING_EMPLOYEE_QUERY).FirstOrDefault <Employee>(); if (resultFound == null) { Employee entity = dataService.Add <Employee>(syncObjects.EmployeeList[i]); syncObjects.EmployeeList[i] = entity; syncObjects.IsEmployeeSync = true; } else { syncObjects.EmployeeList[i] = resultFound; } } syncObjects = syncRepository.Save(controller, syncObjects); return(syncObjects); } catch (Intuit.Ipp.Exception.FaultException ex) { throw ex; } catch (Intuit.Ipp.Exception.InvalidTokenException ex) { throw ex; } catch (Intuit.Ipp.Exception.SdkException ex) { throw ex; } }