public ActionResult CreateEvent(Models.Event newEvent) { ImpersonateUser(newEvent.UserId); if (newEvent.Start > newEvent.End) { ModelState.AddModelError("End", "End time cannot be before start time"); } if (ModelState.IsValid) { try { CronofyHelper.UpsertEvent(newEvent.EventId, newEvent.CalendarId, newEvent.Summary, newEvent.Description, newEvent.Start, newEvent.End); } catch (CronofyResponseException ex) { newEvent.SetError(ex); } if (newEvent.NoErrors()) { return(new RedirectResult(String.Format("/serviceaccountusers/show/{0}/calendar/{1}", newEvent.UserId, newEvent.CalendarId))); } } ViewData["calendarName"] = CronofyHelper.GetCalendars().First(x => x.CalendarId == newEvent.CalendarId).Name; return(View("NewEvent", newEvent)); }
public ActionResult Create(Models.Channel channel) { if (ModelState.IsValid) { var url = ConfigurationManager.AppSettings["domain"] + "/push/channel/" + channel.Path; try { CronofyHelper.CreateChannel(url, channel.OnlyManaged, channel.CalendarIds); } catch (CronofyResponseException ex) { channel.SetError(ex); } if (channel.NoErrors()) { return(new RedirectResult("/channels")); } } ViewData["domain"] = ConfigurationManager.AppSettings["domain"]; ViewData["calendars"] = CronofyHelper.GetCalendars(); return(View("New", channel)); }
public ActionResult Update(Models.Event editEvent) { if (editEvent.Start > editEvent.End) { ModelState.AddModelError("End", "End time cannot be before start time"); } if (ModelState.IsValid) { try { CronofyHelper.UpsertEvent(editEvent.EventId, editEvent.CalendarId, editEvent.Summary, editEvent.Description, editEvent.Start, editEvent.End, new Cronofy.Location(editEvent.LocationDescription, editEvent.Latitude, editEvent.Longitude)); } catch (CronofyResponseException ex) { editEvent.SetError(ex); } if (editEvent.NoErrors()) { return(new RedirectResult(String.Format("/calendars/show/{0}", editEvent.CalendarId))); } } editEvent.Calendar = CronofyHelper.GetCalendars().First(x => x.CalendarId == editEvent.CalendarId); return(View("Edit", editEvent)); }
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 EnterpriseConnect() { var token = CronofyHelper.GetEnterpriseConnectOAuthToken(Request.QueryString["code"]); CronofyHelper.SetToken(token, true); var userInfo = CronofyHelper.GetEnterpriseConnectUserInfo(); var recordCount = Convert.ToInt32(DatabaseHandler.Scalar("SELECT COUNT(*) FROM UserCredentials WHERE CronofyUID=@cronofyUid AND ServiceAccount=1", new Dictionary <string, object> { { "cronofyUid", userInfo.Sub } })); if (recordCount == 0) { DatabaseHandler.ExecuteNonQuery("INSERT INTO UserCredentials(CronofyUID, AccessToken, RefreshToken, ServiceAccount) VALUES(@cronofyUid, @accessToken, @refreshToken, 1)", new Dictionary <string, object> { { "cronofyUid", userInfo.Sub }, { "accessToken", token.AccessToken }, { "refreshToken", token.RefreshToken } }); LogHelper.Log(String.Format("Create enterprise connect user credentials record - sub=`{0}`", userInfo.Sub)); } else { DatabaseHandler.ExecuteNonQuery("UPDATE UserCredentials SET AccessToken=@accessToken, RefreshToken=@refreshToken WHERE CronofyUID=@cronofyUid", new Dictionary <string, object> { { "accessToken", token.AccessToken }, { "refreshToken", token.RefreshToken }, { "cronofyUid", userInfo.Sub } }); LogHelper.Log(String.Format("Update enterprise connect user credentials record - sub=`{0}`", userInfo.Sub)); } Response.SetCookie(new HttpCookie(CronofyHelper.EnterpriseConnectCookieName, userInfo.Sub)); return(new RedirectResult("/enterpriseconnect")); }
public ActionResult Show(string id) { var calendar = CronofyHelper.GetCalendars().First(x => x.CalendarId == id); ViewData["events"] = CronofyHelper.ReadEventsForCalendar(id); return(View("Show", calendar)); }
public ActionResult Show(string id) { var shownEvent = CronofyHelper.ReadEvents().First(x => x.EventUid == id); ViewData["calendarName"] = CronofyHelper.GetCalendars().First(x => x.CalendarId == shownEvent.CalendarId).Name; ViewData["google_maps_embed_api_key"] = ConfigurationManager.AppSettings["google_maps_embed_api_key"]; return(View("Show", shownEvent)); }
private void ImpersonateUser(string userId) { var user = DatabaseHandler.Get <User>("SELECT CronofyUID, AccessToken, RefreshToken from UserCredentials WHERE CronofyUID=@userId AND ServiceAccount=0", new Dictionary <string, object> { { "userId", userId } }); CronofyHelper.SetToken(user.AccessToken, user.RefreshToken, false); }
public ActionResult Index() { var calendars = CronofyHelper.GetCalendars(); var freeBusy = CronofyHelper.GetFreeBusy(); var model = freeBusy .GroupBy(x => x.CalendarId) .ToDictionary(x => calendars.First(cal => cal.CalendarId == x.Key), x => x.ToList()); return(View("Index", model)); }
public ActionResult Show(string id) { var channel = CronofyHelper.GetChannels().First(x => x.Id == id); ViewData["Data"] = DatabaseHandler.Many <Persistence.Models.ChannelData>("SELECT ChannelId, Record, OccurredOn FROM ChannelData WHERE ChannelId=@channelId ORDER BY OccurredOn DESC", new Dictionary <string, object> { { "channelId", channel.Id } }); return(View("Show", channel)); }
public ActionResult Calendar(string userId, string calendarId) { ImpersonateUser(userId); var calendar = CronofyHelper.GetCalendars().First(x => x.CalendarId == calendarId); ViewData["userId"] = userId; ViewData["events"] = CronofyHelper.ReadEventsForCalendar(calendarId); return(View("Calendar", calendar)); }
public ActionResult New([Bind(Prefix = "id")] string profileId) { ViewData["profileName"] = CronofyHelper.GetProfiles().First(x => x.Id == profileId).Name; var calendar = new Models.Calendar { ProfileId = profileId, }; return(View("New", calendar)); }
public ActionResult New([Bind(Prefix = "id")] string calendarId) { var newEvent = new Models.Event { Calendar = CronofyHelper.GetCalendars().First(x => x.CalendarId == calendarId), CalendarId = calendarId, EventId = "unique_event_id_" + (new Random().Next(0, 1000000).ToString("D6")) }; return(View("New", newEvent)); }
public ActionResult Index() { var profiles = new Dictionary <Cronofy.Profile, Cronofy.Calendar[]>(); var calendars = CronofyHelper.GetCalendars(); foreach (var profile in CronofyHelper.GetProfiles()) { profiles.Add(profile, calendars.Where(x => x.Profile.ProfileId == profile.Id).ToArray()); } return(View(profiles)); }
public ActionResult Index() { ViewData["resources"] = CronofyHelper.GetResources(); var users = DatabaseHandler.Many <Persistence.Models.EnterpriseConnectUserData>("SELECT CronofyUID, Email, Status FROM EnterpriseConnectUserData WHERE OwnedBy=@ownedBy", new Dictionary <string, object> { { "ownedBy", uidCookie.Value } }); ViewData["users"] = users; return(View()); }
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 New() { var calendars = CronofyHelper.GetCalendars(); var channel = new Models.Channel { CalendarIds = calendars.Select(x => x.CalendarId).ToArray(), }; ViewData["domain"] = ConfigurationManager.AppSettings["domain"]; ViewData["calendars"] = calendars; return(View("New", channel)); }
public ActionResult AccountId(string code) { try { var token = CronofyHelper.GetAccountIdOAuthToken(code); ViewData["AccountId"] = token.AccountId; ViewData["AuthUrl"] = CronofyHelper.GetAccountIdAuthUrl(); } catch { return(new RedirectResult(CronofyHelper.GetAccountIdAuthUrl())); } return(View()); }
public ActionResult NewEvent(string userId, string calendarId) { ImpersonateUser(userId); ViewData["calendarName"] = CronofyHelper.GetCalendars().First(x => x.CalendarId == calendarId).Name; var newEvent = new Models.Event { UserId = userId, CalendarId = calendarId, EventId = "unique_event_id_" + (new Random().Next(0, 1000000).ToString("D6")) }; return(View("NewEvent", newEvent)); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { var cronofyCookie = Request.Cookies.Get(CronofyHelper.CookieName); if (cronofyCookie == null) { filterContext.Result = new RedirectResult("/login"); } else if (!CronofyHelper.LoadUser(cronofyCookie.Value, false)) { Response.Cookies.Remove(CronofyHelper.CookieName); filterContext.Result = new RedirectResult("/login"); } base.OnActionExecuting(filterContext); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { uidCookie = Request.Cookies.Get(CronofyHelper.EnterpriseConnectCookieName); if (uidCookie == null) { filterContext.Result = new RedirectResult("/login/enterpriseconnect"); } else if (!CronofyHelper.LoadUser(uidCookie.Value, true)) { Response.Cookies.Remove(CronofyHelper.EnterpriseConnectCookieName); filterContext.Result = new RedirectResult("/login/enterpriseconnect"); } base.OnActionExecuting(filterContext); }
public ActionResult Authorize([Bind(Prefix = "id")] string enterpriseConnectId, string email) { LogHelper.Log(String.Format("Receive Service Account callback - enterpriseConnectId=`{0}`", enterpriseConnectId)); try { var inputStream = Request.InputStream; inputStream.Seek(0, SeekOrigin.Begin); var body = new StreamReader(inputStream).ReadToEnd(); var data = JsonConvert.DeserializeObject <ServiceAccountAuthorizationData>(body); if (data.Authorization.Error != null) { DatabaseHandler.ExecuteNonQuery("UPDATE EnterpriseConnectUserData SET Status=@status WHERE Email=@email AND OwnedBy=@ownedBy", new Dictionary <string, object> { { "status", (int)EnterpriseConnectUserData.ConnectedStatus.Failed }, { "email", email }, { "ownedBy", enterpriseConnectId } }); LogHelper.Log(String.Format("Service Account callback failure - error=`{0}` - error_key=`{1}` - error_description=`{2}`", data.Authorization.Error, data.Authorization.ErrorKey, data.Authorization.ErrorDescription)); } else { var userToken = CronofyHelper.GetEnterpriseConnectUserOAuthToken(enterpriseConnectId, email, data.Authorization.Code); DatabaseHandler.ExecuteNonQuery("INSERT INTO UserCredentials(CronofyUID, AccessToken, RefreshToken, ServiceAccount) VALUES(@cronofyUid, @accessToken, @refreshToken, 0)", new Dictionary <string, object> { { "cronofyUid", userToken.LinkingProfile.Id }, { "accessToken", userToken.AccessToken }, { "refreshToken", userToken.RefreshToken } }); DatabaseHandler.ExecuteNonQuery("UPDATE EnterpriseConnectUserData SET Status=@status, CronofyUID=@cronofyUid WHERE Email=@email AND OwnedBy=@ownedBy", new Dictionary <string, object> { { "status", (int)EnterpriseConnectUserData.ConnectedStatus.Linked }, { "cronofyUid", userToken.LinkingProfile.Id }, { "email", userToken.LinkingProfile.Name }, { "ownedBy", enterpriseConnectId } }); LogHelper.Log(String.Format("Service Account callback success - id=`{0}` - email=`{1}`", userToken.LinkingProfile.Id, userToken.LinkingProfile.Name)); } } catch (Exception ex) { LogHelper.Log(String.Format("Service Account callback failure - ex.Source=`{0}` - ex.Message=`{1}`", ex.Source, ex.Message)); } return(new EmptyResult()); }
public ActionResult ViewAvailability(Availability resource) { resource.AuthUrl = CronofyHelper.GetAccountIdAuthUrl(); if (ModelState.IsValid) { try { resource.AvailablePeriods = CronofyHelper.Availability(resource); } catch (CronofyResponseException ex) { resource.SetError(ex); } return(View("Index", resource)); } return(View("Index", resource)); }
public ActionResult Create(EnterpriseConnectUser user) { if (ModelState.IsValid) { try { CronofyHelper.AuthorizeWithServiceAccount(uidCookie.Value, user.Email, user.Scopes); } catch (CronofyResponseException ex) { user.SetError(ex); } if (user.NoErrors()) { var recordCount = Convert.ToInt32(DatabaseHandler.Scalar("SELECT COUNT(1) FROM EnterpriseConnectUserData WHERE Email=@email AND OwnedBy=@ownedBy", new Dictionary <string, object> { { "email", user.Email }, { "ownedBy", uidCookie.Value } })); if (recordCount == 0) { DatabaseHandler.ExecuteNonQuery("INSERT INTO EnterpriseConnectUserData(Email, OwnedBy, Status) VALUES(@email, @ownedBy, @status)", new Dictionary <string, object> { { "email", user.Email }, { "ownedBy", uidCookie.Value }, { "status", (int)EnterpriseConnectUserData.ConnectedStatus.Pending } }); } else { DatabaseHandler.ExecuteNonQuery("UPDATE EnterpriseConnectUserData SET Status=@status WHERE Email=@email AND OwnedBy=@ownedBy", new Dictionary <string, object> { { "status", (int)EnterpriseConnectUserData.ConnectedStatus.Pending }, { "email", user.Email }, { "ownedBy", uidCookie.Value } }); } return(new RedirectResult("/enterpriseconnect")); } } return(View("New", user)); }
public ActionResult Show([Bind(Prefix = "id")] string userId) { var enterpriseConnectData = DatabaseHandler.Get <EnterpriseConnectUserData>("SELECT CronofyUID, Email, Status FROM EnterpriseConnectUserData WHERE CronofyUID=@userId AND OwnedBy=@uidCookie", new Dictionary <string, object> { { "userId", userId }, { "uidCookie", uidCookie.Value } }); ImpersonateUser(userId); var profiles = new Dictionary <Cronofy.Profile, Cronofy.Calendar[]>(); var calendars = CronofyHelper.GetCalendars(); foreach (var profile in CronofyHelper.GetProfiles()) { profiles.Add(profile, calendars.Where(x => x.Profile.ProfileId == profile.Id).ToArray()); } ViewData["profiles"] = profiles; return(View("Show", enterpriseConnectData)); }
public ActionResult Edit(string id) { var gotEvent = CronofyHelper.ReadEvents().First(x => x.EventUid == id); var editEvent = new Models.Event { Calendar = CronofyHelper.GetCalendars().First(x => x.CalendarId == gotEvent.CalendarId), CalendarId = gotEvent.CalendarId, EventId = gotEvent.EventId, Summary = gotEvent.Summary, Description = gotEvent.Description, Start = (gotEvent.Start.HasTime ? gotEvent.Start.DateTimeOffset.DateTime : gotEvent.Start.Date.DateTime), End = (gotEvent.End.HasTime ? gotEvent.End.DateTimeOffset.DateTime : gotEvent.End.Date.DateTime), LocationDescription = gotEvent.Location == null ? null : gotEvent.Location.Description, Latitude = gotEvent.Location == null ? null : gotEvent.Location.Latitude, Longitude = gotEvent.Location == null ? null : gotEvent.Location.Longitude }; return(View("Edit", editEvent)); }
public ActionResult Create(Models.Calendar calendar) { if (ModelState.IsValid) { try { CronofyHelper.CreateCalendar(calendar.ProfileId, calendar.Name); } catch (CronofyResponseException ex) { calendar.SetError(ex); } if (calendar.NoErrors()) { return(new RedirectResult("/profiles")); } } ViewData["profileName"] = CronofyHelper.GetProfiles().First(x => x.Id == calendar.ProfileId).Name; return(View("New", calendar)); }
public ActionResult EnterpriseConnect() { ViewData["authUrl"] = CronofyHelper.GetEnterpriseConnectAuthUrl(); return(View("EnterpriseConnect")); }
public ActionResult Index() { ViewData["authUrl"] = CronofyHelper.GetAuthUrl(); return(View()); }
public ActionResult Delete(Models.Event deleteEvent) { CronofyHelper.DeleteEvent(deleteEvent.CalendarId, deleteEvent.EventId); return(new RedirectResult(String.Format("/calendars/show/{0}", deleteEvent.CalendarId))); }