public override bool ProcessUpdate(Item oldItem, Item newItem) { GoogleClient client = new GoogleClient(user, storage); if (newItem.ItemTypeID != oldItem.ItemTypeID) { // remove appointment from Calendar if ItemType changes ProcessDelete(oldItem); // base handles ItemType changing return base.ProcessUpdate(oldItem, newItem); } // update appointment on Calendar (if available) if (client.ConnectToCalendar) { // update if Name, DueDate, EndDate, or Description have changed FieldValue fvOldStart = oldItem.GetFieldValue(FieldNames.DueDate); FieldValue fvNewStart = newItem.GetFieldValue(FieldNames.DueDate); FieldValue fvOldEnd = oldItem.GetFieldValue(FieldNames.EndDate); FieldValue fvNewEnd = newItem.GetFieldValue(FieldNames.EndDate); FieldValue fvOldDesc = oldItem.GetFieldValue(FieldNames.Description); FieldValue fvNewDesc = newItem.GetFieldValue(FieldNames.Description); string oldDesc = (fvOldDesc == null) ? null : fvOldDesc.Value; string newDesc = (fvNewDesc == null) ? null : fvNewDesc.Value; if (newItem.Name != oldItem.Name || newDesc != oldDesc || (fvNewStart != null && !string.IsNullOrEmpty(fvNewStart.Value) && (fvOldStart == null || fvNewStart.Value != fvOldStart.Value)) || (fvNewEnd != null && !string.IsNullOrEmpty(fvNewEnd.Value) && (fvOldEnd == null || fvNewEnd.Value != fvOldEnd.Value))) { if (fvNewStart != null && fvNewEnd != null) { return client.UpdateCalendarEvent(newItem); } } } return false; }
// entry point to verify Google consent it working public ActionResult AccessGoogle() { GoogleClient client = new GoogleClient(this.CurrentUser, this.StorageContext); client.ForceAuthentication(); return RedirectToAction("Home", "Dashboard"); }
public override bool ProcessDelete(Item item) { if (base.ProcessDelete(item)) return true; // delete appointment from Calendar (if available) GoogleClient client = new GoogleClient(user, storage); if (client.ConnectToCalendar) { return client.RemoveCalendarEvent(item); } return false; }
public override bool ProcessCreate(Item item) { // base method extracts intent if (base.ProcessCreate(item)) return true; // add new appointment to Calendar (if available) GoogleClient client = new GoogleClient(user, storage); if (client.ConnectToCalendar) { return client.AddCalendarEvent(item); } return false; }
public ActionResult Google() { if (googleClient == null) { // access Google Calendar API to force initial authentication googleClient = new GoogleClient(); } if (HttpContext.Request["code"] != null) { // load access tokens googleClient.Authenticator.LoadAccessToken(); } try { // force authentication by accessing calendar settings googleClient.ForceAuthentication(); return RedirectToAction("Home", "Dashboard", new { consentStatus = UserDataModel.GoogleConsentSuccess }); } catch (ThreadAbortException) { throw; } catch (Exception) { return RedirectToAction("Home", "Dashboard", new { consentStatus = UserDataModel.GoogleConsentFail }); } }