public ActionResult Index() { var token = CronofyHelper.GetOAuthToken(Request.QueryString["code"]); CronofyHelper.SetToken(token, false); var account = CronofyHelper.GetAccount(); var recordCount = Convert.ToInt32(DatabaseHandler.Scalar("SELECT COUNT(*) FROM UserCredentials WHERE CronofyUID=@accountId AND ServiceAccount=0", new Dictionary <string, object> { { "accountId", account.Id } })); if (recordCount == 0) { DatabaseHandler.ExecuteNonQuery("INSERT INTO UserCredentials(CronofyUID, AccessToken, RefreshToken, ServiceAccount) VALUES(@cronofyUid, @accessToken, @refreshToken, 0)", new Dictionary <string, object> { { "cronofyUid", account.Id }, { "accessToken", token.AccessToken }, { "refreshToken", token.RefreshToken } }); LogHelper.Log(String.Format("Create user credentials record - accountId=`{0}`", account.Id)); } else { DatabaseHandler.ExecuteNonQuery("UPDATE UserCredentials SET AccessToken=@accessToken, RefreshToken=@refreshToken WHERE CronofyUID=@cronofyUid", new Dictionary <string, object> { { "accessToken", token.AccessToken }, { "refreshToken", token.RefreshToken }, { "cronofyUid", account.Id } }); LogHelper.Log(String.Format("Update user credentials record - accountId=`{0}`", account.Id)); } Response.SetCookie(new HttpCookie(CronofyHelper.CookieName, account.Id)); return(new RedirectResult("/")); }
public ActionResult Index() { return(View(new Availability { AuthUrl = CronofyHelper.GetAccountIdAuthUrl(), AccountId1 = CronofyHelper.GetAccount().Id, RequiredParticipants = "all", Duration = 60, Start = DateTime.Now.Date.AddDays(1), End = DateTime.Now.Date.AddDays(2), })); }
public ActionResult Index() { CronofyHelper.GetAccount(); return(View()); }