public ActionResult Create(CalendarEvent calendarEvent)
        {
            if (ModelState.IsValid)
            {
                var authenticator = GetAuthenticator();
                var service = new GoogleCalendarServiceProxy(authenticator);

                service.CreateEvent(calendarEvent);
            }

            return RedirectToAction("Index", "Home");
        }
        // see https://developers.google.com/google-apps/calendar/v3/reference/events/insert
        public bool CreateEvent(CalendarEvent calendarEvent)
        {
            var calendarService = new CalendarService(_authenticator);
            var calendar = GetCalendar(calendarEvent.CalendarId);

            Event newEvent = new Event()
            {
                Summary = calendarEvent.Title,
                Location = calendarEvent.Location,
                Description = calendarEvent.Description,
                Start = new EventDateTime() { DateTime = calendarEvent.StartDate.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffK") },
                End = new EventDateTime() { DateTime = calendarEvent.EndDate.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffK") },
                Attendees = (calendarEvent.Attendees != null) ? calendarEvent.Attendees.Select(email => new EventAttendee { Email = email }).ToList<EventAttendee>() : null,
                ColorId = ((int)calendarEvent.ColorId).ToString()
            };

            var result = calendarService.Events.Insert(newEvent, calendar.Id).Fetch();

            return result != null;
        }
        public ActionResult Create()
        {
            string calendarId = string.Empty;
            using (var context = new UsersContext())
            {
                calendarId = context.UserProfiles.FirstOrDefault(c => c.UserName == User.Identity.Name).Email;
            }

            var model = new CalendarEvent()
            {
                CalendarId = calendarId,
                Title = "Stand up meeting",
                Location = "Starbucks",
                StartDate = DateTime.Today,
                EndDate = DateTime.Today.AddMinutes(60),
                Description = "Let's start this day with a great cup of coffee"
            };
            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);
        }
        // see https://developers.google.com/google-apps/calendar/v3/reference/events/update
        public bool UpdateEvent(CalendarEvent calendarEvent)
        {
            var calendarService = new CalendarService(_authenticator);
            var calendar = GetCalendar(calendarEvent.CalendarId);
            var toUpdate = calendarService.Events.Get(calendarEvent.CalendarId, calendarEvent.Id).Fetch();
            if (toUpdate == null) throw new GoogleCalendarServiceProxyException("There is no event stored in the calendar with that id");

            toUpdate.Summary = calendarEvent.Title;
            toUpdate.Location = calendarEvent.Location;
            toUpdate.Description = calendarEvent.Description;
            toUpdate.Start = new EventDateTime() { DateTime = calendarEvent.StartDate.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffK") };
            toUpdate.End = new EventDateTime() { DateTime = calendarEvent.EndDate.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffK") };
            toUpdate.ColorId = ((int)calendarEvent.ColorId).ToString();

            if(calendarEvent.Attendees != null && calendarEvent.Attendees.Count() > 0 && !string.IsNullOrEmpty(calendarEvent.Attendees.First()))
            {
                toUpdate.Attendees = calendarEvent.Attendees.Select(email => new EventAttendee { Email = email }).ToList<EventAttendee>();
            }

            var result = calendarService.Events.Update(toUpdate, calendar.Id, calendarEvent.Id).Fetch();

            return result != null;
        }