Beispiel #1
0
        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 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));
        }