//
        // GET: /CalendarEvent/Delete?calendarId={calendarId}&eventId={eventId}
        public ActionResult Delete(string calendarId, string eventId)
        {
            var authenticator = GetAuthenticator();
            var service = new GoogleCalendarServiceProxy(authenticator);
            service.DeleteEvent(calendarId, eventId);

            return RedirectToAction("Index", "Home");
        }
        //
        // GET: /CalendarEvent/Edit?calendarId={calendarId}&eventId={eventId}
        public ActionResult Edit(string calendarId, string eventId)
        {
            var authenticator = GetAuthenticator();
            var service = new GoogleCalendarServiceProxy(authenticator);
            var model = service.GetEvent(calendarId, eventId);
            var colorList = Enum.GetValues(typeof(GoogleEventColors)).Cast<GoogleEventColors>()
                                .Select(v => new SelectListItem { Text = v.ToString(), Value = ((int)v).ToString() });

            ViewBag.Colors = new SelectList(colorList, "Value", "Text");
            return View(model);
        }
        public ActionResult Create(CalendarEvent calendarEvent)
        {
            if (ModelState.IsValid)
            {
                var authenticator = GetAuthenticator();
                var service = new GoogleCalendarServiceProxy(authenticator);

                service.CreateEvent(calendarEvent);
            }

            return RedirectToAction("Index", "Home");
        }
        public ActionResult ListEvents(DateTime startDate, DateTime endDate)
        {
            UserProfile userProfile = null;
            using(var context = new UsersContext())
            {
                userProfile = context.UserProfiles.FirstOrDefault(c => c.UserName == User.Identity.Name);
            }

            if (userProfile == null) return RedirectToAction("Register", "Account");

            var authenticator = GetAuthenticator();

            var service = new GoogleCalendarServiceProxy(authenticator);
            var model = service.GetEvents(userProfile.Email, startDate, endDate);

            ViewBag.StartDate = startDate.ToShortDateString();
            ViewBag.EndDate = endDate.ToShortDateString();
            return View("Index", model);
        }