示例#1
0
        // entry point to verify Google consent is working
        public ActionResult AccessGoogle()
        {
            GoogleClient client = new GoogleClient(this.CurrentUser, this.StorageContext);
            client.ForceAuthentication();

            return RedirectToAction("Home", "Dashboard");
        }
示例#2
0
        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;
        }
示例#3
0
 public ActionResult CreateNextSteps()
 {
     var jsResult = new JsResult();
     GoogleClient client = new GoogleClient(CurrentUser, StorageContext);
     if (!client.AddNextStepsEvent(null))
         jsResult.StatusCode = HttpStatusCode.NotFound;
     JsonResult result = new JsonResult();
     result.Data = jsResult;
     return Json(result, JsonRequestBehavior.AllowGet);
 }
示例#4
0
        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;
        }
示例#5
0
        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;
        }
示例#6
0
        public ActionResult CreateAppointment(Appointment appointment)
        {
            GoogleClient client = new GoogleClient(CurrentUser, StorageContext);
            var item = client.AddCalendarEvent(appointment);
            var appointmentResult = new JsAppointmentResult();
            if (item != null)
                appointmentResult.Result = item;
            else
                appointmentResult.StatusCode = HttpStatusCode.InternalServerError;

            JsonResult result = new JsonResult();
            result.Data = appointmentResult;
            return result;
        }
示例#7
0
        public ActionResult Google(string id)
        {
            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();
                if (id == null)
                    return RedirectToAction("Home", "Dashboard", new { consentStatus = UserDataModel.GoogleConsentSuccess });
                else
                    return RedirectToAction("Wizard", "UserInfo", new { consentStatus = UserDataModel.GoogleConsentSuccess });
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception)
            {
                if (id == null)
                    return RedirectToAction("Home", "Dashboard", new { consentStatus = UserDataModel.GoogleConsentFail });
                else
                    return RedirectToAction("Wizard", "UserInfo", new { consentStatus = UserDataModel.GoogleConsentFail });
            }
        }