/// <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);
     }
 }
 /// <summary>
 /// Sequence:
 /// -->Retrieve the Request token
 /// -->Retrieve the value from query string
 /// -->Retrieve acces token
 /// -->Retrieve acces secret
 /// -->Redirect to close
 /// </summary>
 /// <returns></returns>
 public ActionResult Response()
 {
     oAuthorizationDB = new OAuthTokens();
     oAuthService = new OAuthService(oAuthorizationdto);
     oAuthorizationdto = oAuthService.GetRequestToken(this);
     if (Request.QueryString.HasKeys())
     {
         oAuthorizationdto.OauthVerifyer = Request.QueryString["oauth_verifier"].ToString();
         oAuthorizationDB.realmid = Convert.ToInt32(Request.QueryString["realmId"].ToString());
         oAuthorizationdto.Realmid = oAuthorizationDB.realmid;
         oAuthorizationDB.datasource = Request.QueryString["dataSource"].ToString();
         oAuthorizationdto.DataSource = oAuthorizationDB.datasource;
         oAuthorizationdto = oAuthService.GetAccessTokenFromServer(this,oAuthorizationdto);
         //encrypt the tokens
         oAuthorizationDB.access_secret = Utility.Encrypt(oAuthorizationdto.AccessTokenSecret, oAuthorizationdto.SecurityKey);
         oAuthorizationDB.access_token = Utility.Encrypt(oAuthorizationdto.AccessToken, oAuthorizationdto.SecurityKey);
         using (var oAuthorizationDBContext = new OAuthdataContext("DBContext"))
         {
             //store the encrypted tokens to DB.
             oAuthorizationDBContext.Tokens.Add(oAuthorizationDB);
             oAuthorizationDBContext.SaveChanges();
         }
     }
     return RedirectToAction("Close", "Home");
 }
 /// <summary>
 /// Action Result for Index, This flow will create OAuthConsumer Context using Consumer key and Consuler Secret key
 /// obtained when Application is added at intuit workspace. It creates OAuth Session out of OAuthConsumer and Calls 
 /// Intuit Workpsace endpoint for OAuth.
 /// </summary>
 /// <returns>Redirect Result.</returns>
 public RedirectResult Index()
 {
     oAuthorizationdto = new OAuthorizationdto();
     oAuthService = new OAuthService(oAuthorizationdto);
     oAuthorizationdto.CallBackUrl = Request.Url.GetLeftPart(UriPartial.Authority) + "/Oauth/Response";
     return Redirect(oAuthService.GrantUrl(this));
 }
 /// <summary>
 /// Sequence :
 /// -->Get Token
 /// -->Get data to be pushed to QBO
 /// -->Call the service
 /// 
 /// </summary>
 /// <param name="id"></param>
 /// <returns>RedirectToAction</returns>
 public ActionResult Customer(Int64 id)
 {
     OAuthorizationdto oAuthDetails = new OAuthService(new OAuthorizationdto()).GetAccessToken(this);
     syncService = new SyncService(oAuthDetails);
     syncObjects = id > 0 ? syncService.GetSyncObjects(this, id) : new Syncdto();
     syncObjects.OauthToken = oAuthDetails;
     syncObjects.CompanyId = oAuthDetails.Realmid;
  
     if (!syncService.IsCustSync(syncObjects, syncService).IsCustomerSync)
     {
         syncObjects = syncService.GetDatafromDBCustomer(syncObjects);
         if (syncObjects.CustomerList.Count>0)
         {
             syncObjects = syncService.SyncCustomer(this, syncObjects);
         }
     }
     return RedirectToAction("Sync", "Home", new { id = syncObjects.Id, isConnected = oAuthDetails.IsConnected });
 }