/// <summary>
        /// Launchs the create new event controller.
        /// </summary>
        protected void LaunchModifyEvent()
        {
            // first we need to create an event it so we have one that we know exists
            // in a real world scenario, we'd likely either a) be modifying an event that
            // we found via a query, or 2) we'd do like this, in which we'd automatically
            // populate the event data, like for say a dr. appt. reminder, or something
            EKEvent newEvent = EKEvent.FromStore(CalendarParam.Current.EventStore);

            // set the alarm for 10 minutes from now
            newEvent.AddAlarm(EKAlarm.FromDate((NSDate)DateTime.FromFileTime(wkBooking.starting.ToFileTime())));
            // make the event start 20 minutes from now and last 30 minutes
            newEvent.StartDate = (NSDate)DateTime.Now.AddMinutes(20);
            newEvent.EndDate   = (NSDate)DateTime.Now.AddMinutes(50);
            newEvent.Title     = wkBooking.topic;
            newEvent.Location  = AppParam.campusName;
            newEvent.Notes     = wkBooking.description;


            // create a new EKEventEditViewController. This controller is built in an allows
            // the user to create a new, or edit an existing event.
            EventKitUI.EKEventEditViewController eventController =
                new EventKitUI.EKEventEditViewController();

            // set the controller's event store - it needs to know where/how to save the event
            eventController.EventStore = CalendarParam.Current.EventStore;
            eventController.Event      = newEvent;

            // wire up a delegate to handle events from the controller
            eventControllerDelegate          = new CreateEventEditViewDelegate(eventController);
            eventController.EditViewDelegate = eventControllerDelegate;

            // show the event controller
            PresentViewController(eventController, true, null);
        }
Esempio n. 2
0
        public async Task <string> CreateAlarmAsync(string title, string description, DateTime timeInit, DateTime timeEnd, int alarmMinutes)
        {
            bool hasPermission = await ASkForPermissionsAsync();

            if (!hasPermission)
            {
                return(string.Empty);
            }
            if (appCalendar == null)
            {
                await CreateCalendarForAppAlarmsAsync();
            }

            if (appCalendar != null)
            {
                EKEvent reminder = EKEvent.FromStore(eventsStore);
                reminder.AddAlarm(EKAlarm.FromTimeInterval(-(alarmMinutes * 60)));
                reminder.StartDate = timeInit.ToNSDate();
                reminder.EndDate   = timeEnd.ToNSDate();
                reminder.Title     = title;
                reminder.Notes     = description;
                reminder.Calendar  = appCalendar;
                bool saved = eventsStore.SaveEvent(reminder, EKSpan.ThisEvent, out NSError e);
                if (e == null)
                {
                    return(reminder.CalendarItemIdentifier);
                }
            }

            return(string.Empty);
        }
        void ICalendar.AddToCalendar(GenEvent genEvent)
        {
            var estZone      = TimeZoneInfo.FindSystemTimeZoneById("America/Indiana/Indianapolis");
            var newStartTime = TimeZoneInfo.ConvertTime(genEvent.StartDateTime, estZone, TimeZoneInfo.Local);
            var newEndTime   = TimeZoneInfo.ConvertTime(genEvent.EndDateTime, estZone, TimeZoneInfo.Local);

            eventStore = eventStore ?? new EKEventStore();

            eventStore.RequestAccess(EKEntityType.Event,
                                     (bool granted, NSError e) => {
                if (granted)
                {
                    EKEventStore eventStore = new EKEventStore();

                    //Insert the data into the agenda.
                    EKEvent newEvent   = EKEvent.FromStore(eventStore);
                    newEvent.StartDate = CalendarHelpers.DateTimeToNSDate(newStartTime);
                    newEvent.EndDate   = CalendarHelpers.DateTimeToNSDate(newEndTime);
                    newEvent.Title     = genEvent.Title;
                    newEvent.Notes     =
                        genEvent.Location + "\r\n\r\n"
                        + genEvent.Description + "\r\n\r\n"
                        + genEvent.LiveURL
                    ;

                    EKAlarm[] alarmsArray = new EKAlarm[1];
                    alarmsArray[0]        = EKAlarm.FromDate(newEvent.StartDate.AddSeconds(-600));
                    newEvent.Alarms       = alarmsArray;

                    newEvent.Calendar = eventStore.DefaultCalendarForNewEvents;
                    eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, true, out e);
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        //bool returned = await GlobalVars.notifier.Notify(ToastNotificationType.Success,
                        //    "Event added!", genEvent.Title + " has been added to your calendar!", TimeSpan.FromSeconds(3));
                        //var returned = await GlobalVars.notifier.Notify(new NotificationOptions()
                        //{
                        //    Title = "Event added!",
                        //    Description = genEvent.Title + " has been added to your calendar!",
                        //});
                        GlobalVars.DoToast(genEvent.Title + " has been added to your calendar!", GlobalVars.ToastType.Green);
                    });
                }
                //do something here
                else
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        //bool returned = await GlobalVars.notifier.Notify(ToastNotificationType.Error,
                        //    "Don't have permission!", "You need to allow this app to access the calendar first. Please change the setting in Settings -> Privacy -> Calendars.", TimeSpan.FromSeconds(4));
                        //var returned = await GlobalVars.notifier.Notify(new NotificationOptions()
                        //{
                        //    Title = "Don't have permission!",
                        //    Description = "You need to allow this app to access the calendar first. Please change the setting in Settings -> Privacy -> Calendars.",
                        //});
                        GlobalVars.DoToast("Need permission - you need to allow this app to access the calendar first. Please change the setting in Settings -> Privacy -> Calendars.", GlobalVars.ToastType.Red, 5000);
                    });
                }
            });
        }
Esempio n. 4
0
 public void NullAllowedTest()
 {
     using (var alarm = EKAlarm.FromTimeInterval(1234)) {
         alarm.AbsoluteDate       = null;
         alarm.StructuredLocation = null;
     }
 }
Esempio n. 5
0
        public Task <bool> AddReminderAsync(string id, CalendarEvent calEvent)
        {
            bool success = true;

            EventStore.RequestAccess(
                EKEntityType.Event,
                (granted, e) =>
            {
                if (granted)
                {
                    var newEvent = EKEvent.FromStore(EventStore);

                    newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(calEvent.Start.AddMinutes(-15))));
                    newEvent.StartDate = DateTimeToNSDate(calEvent.Start);
                    newEvent.EndDate   = DateTimeToNSDate(calEvent.End);
                    newEvent.Title     = calEvent.Name;
                    newEvent.Notes     = calEvent.Description;
                    newEvent.Location  = calEvent.Location;
                    newEvent.AllDay    = calEvent.AllDay;

                    newEvent.Calendar = EventStore.DefaultCalendarForNewEvents;
                }
                else
                {
                    this.contentDialogService.Alert("Access Denied", "User Denied Access to Calendar Data");
                    success = false;
                }
            });

            return(Task.FromResult(success));
        }
Esempio n. 6
0
        public void SetEvent(DateTime date, string title, string note)
        {
            if (eventStore == null)
            {
                requestAccess();
            }

            // set the controller's event store - it needs to know where/how to save the event
            eventController.EventStore = eventStore;


            NSDate date2 = DateTimeToNSDate2(date);

            EKEvent newEvent = EKEvent.FromStore(eventController.EventStore);

            // set the alarm for 10 minutes from now

            newEvent.AddAlarm(EKAlarm.FromDate(date2));
            // make the event start 20 minutes from now and last 30 minutes
            newEvent.StartDate = date2;
            newEvent.EndDate   = date2.AddSeconds(1800);
            newEvent.Title     = title;
            newEvent.Notes     = note;
            newEvent.Calendar  = eventController.EventStore.DefaultCalendarForNewEvents;
            NSError a;

            eventController.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out a);
            Console.WriteLine("Event Saved, ID: " + newEvent.CalendarItemIdentifier);
        }
        /// <summary>
        /// Launchs the create new event controller.
        /// </summary>
        protected void LaunchModifyEvent()
        {
            // first we need to create an event it so we have one that we know exists
            // in a real world scenario, we'd likely either a) be modifying an event that
            // we found via a query, or 2) we'd do like this, in which we'd automatically
            // populate the event data, like for say a dr. appt. reminder, or something
            EKEvent newEvent = EKEvent.FromStore(App.Current.EventStore);

            // set the alarm for 10 minutes from now
            newEvent.AddAlarm(EKAlarm.FromDate(DateTime.Now.AddMinutes(10)));
            // make the event start 20 minutes from now and last 30 minutes
            newEvent.StartDate = DateTime.Now.AddMinutes(20);
            newEvent.EndDate   = DateTime.Now.AddMinutes(50);
            newEvent.Title     = "Get outside and do some exercise!";
            newEvent.Notes     = "This is your motivational event to go and do 30 minutes of exercise. Super important. Do this.";

            // create a new EKEventEditViewController. This controller is built in an allows
            // the user to create a new, or edit an existing event.
            MonoTouch.EventKitUI.EKEventEditViewController eventController =
                new MonoTouch.EventKitUI.EKEventEditViewController();

            // set the controller's event store - it needs to know where/how to save the event
            eventController.EventStore = App.Current.EventStore;
            eventController.Event      = newEvent;

            // wire up a delegate to handle events from the controller
            eventControllerDelegate          = new CreateEventEditViewDelegate(eventController);
            eventController.EditViewDelegate = eventControllerDelegate;

            // show the event controller
            PresentViewController(eventController, true, null);
        }
Esempio n. 8
0
 public void NullAllowedTest()
 {
     using (var alarm = new EKAlarm()) {
         alarm.AbsoluteDate       = null;
         alarm.StructuredLocation = null;
     }
 }
Esempio n. 9
0
        public static EKAlarm ToEKAlarm(this CalendarEventReminder calendarEventReminder)
        {
            // iOS stores in negative seconds before the event, but CalendarEventReminder.TimeBefore uses
            // a positive TimeSpan before the event
            var seconds = -calendarEventReminder.TimeBefore.TotalSeconds;

            return(EKAlarm.FromTimeInterval(seconds));
        }
Esempio n. 10
0
        public void NullAllowedTest()
        {
            TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 8, throwIfOtherPlatform: false);

            using (var alarm = EKAlarm.FromTimeInterval(1234)) {
                alarm.AbsoluteDate       = null;
                alarm.StructuredLocation = null;
            }
        }
Esempio n. 11
0
        private void GenerarEvento(SalaJuntasReservacionModel Reservaciones)
        {
            RequestAccess(EKEntityType.Event, () =>
            {
                CLLocation location = new CLLocation();
                if (Reservaciones.Sucursal_Id == "1")
                {
                    location = new CLLocation(20.6766, -103.3812);
                }
                else
                {
                    location = new CLLocation(20.6766, -103.3812);
                }
                var structuredLocation         = new EKStructuredLocation();
                structuredLocation.Title       = Reservaciones.Sucursal_Domicilio;
                structuredLocation.GeoLocation = location;

                NSDateFormatter dateFormat = new NSDateFormatter();
                dateFormat.DateFormat      = "dd/MM/yyyy";
                NSDate newFormatDate       = dateFormat.Parse(Reservaciones.Sala_Fecha);

                EKEvent newEvent = EKEvent.FromStore(AppHelper.Current.EventStore);

                DateTime myDate = DateTime.ParseExact(Reservaciones.Sala_Fecha, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);

                var arrTime          = Reservaciones.Sala_Hora_Inicio.Split(':');
                var hora             = (double.Parse(arrTime[0]) - 1);
                var minutos          = double.Parse(arrTime[1]);
                var newDate          = myDate.AddHours(hora);
                var newDate2         = newDate.AddMinutes(minutos);
                var HoraAntesReunion = newDate2;
                newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(HoraAntesReunion.AddMinutes(30))));
                newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(HoraAntesReunion.AddMinutes(45))));
                if (newDate2 != null)
                {
                    hora         = hora + 1;
                    var newDate3 = myDate.AddHours(hora);
                    var newDate4 = newDate3.AddMinutes(minutos);

                    var HoraInicio     = this.DateTimeToNSDate(newDate4);
                    newEvent.StartDate = HoraInicio;
                    arrTime            = Reservaciones.Sala_Hora_Fin.Split(':');
                    hora             = double.Parse(arrTime[0]);
                    minutos          = double.Parse(arrTime[1]);
                    var newDate5     = myDate.AddHours(hora);
                    var newDate6     = newDate5.AddMinutes(minutos);
                    newEvent.EndDate = this.DateTimeToNSDate(newDate6);
                }
                newEvent.Title              = "Reservación de sala de juntas en " + Reservaciones.Sucursal_Descripcion + ", en el piso " + Reservaciones.Sala_Nivel + ", en la sala " + Reservaciones.Sala_Descripcion;
                newEvent.Notes              = "Se recomienda presentarse 5 minutos antes de su hora de reservación";
                newEvent.Calendar           = AppHelper.Current.EventStore.DefaultCalendarForNewEvents;
                newEvent.Location           = Reservaciones.Sucursal_Domicilio;
                newEvent.StructuredLocation = structuredLocation;
                NSError e;
                AppHelper.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
            });
        }
Esempio n. 12
0
 public static CalendarEventReminder ToCalendarEventReminder(this EKAlarm alarm)
 {
     return(new CalendarEventReminder
     {
         // iOS stores in negative seconds before the event, but CalendarEventReminder.TimeBefore uses
         // a positive TimeSpan before the event
         TimeBefore = -TimeSpan.FromSeconds(alarm.RelativeOffset)
     });
 }
Esempio n. 13
0
        public void AddReminder(String title, String message, DateTime RemindTime)
        {
            // create a new reminder and set its title and message
            EKReminder reminder = EKReminder.Create(eventStore);

            reminder.Title = title;

            reminder.Notes = message;

            // adding the remind time to the reminder as its due date and alarm time
            // an alarm time
            EKAlarm timeToRing = new EKAlarm();
            NSDate  nsDate     = (NSDate)DateTime.SpecifyKind(RemindTime, DateTimeKind.Utc);

            timeToRing.AbsoluteDate = nsDate;

            reminder.AddAlarm(timeToRing);

            // date components required to add to the reminder
            NSDateComponents dueDate = new NSDateComponents();

            dueDate.Calendar = new NSCalendar(NSCalendarType.Gregorian);
            // all of these value need to be applied induvidualy - although in xcode there is a way to apply them at once
            dueDate.Year   = RemindTime.Year;
            dueDate.Month  = RemindTime.Month;
            dueDate.Day    = RemindTime.Day;
            dueDate.Hour   = RemindTime.Hour;
            dueDate.Minute = RemindTime.Minute;
            dueDate.Second = RemindTime.Second;

            if (dueDate.IsValidDate)
            {
                // well that seems to be a valid date component so lets set the start and due date to it
                reminder.StartDateComponents = dueDate;
                reminder.DueDateComponents   = dueDate;
            }
            // and finnaly lets save it to the phone's calendar - 1st create an error too record to then set the calendar to save to then save to it
            NSError e;

            reminder.Calendar = eventStore.DefaultCalendarForNewReminders;
            eventStore.SaveReminder(reminder, true, out e);
            // alert user if the reminder could not be added
            if (e != null)
            {
                UIAlertController.Create("Failed to add reminder", e.ToString(), UIAlertControllerStyle.Alert);
            }
        }
Esempio n. 14
0
        public async Task <(bool result, CalendarEventModel model)> UpdateCalendarEvent(CalendarEventModel calEvent)
        {
            (bool result, CalendarEventModel model)response = (false, calEvent);

            if (calEvent.DeviceCalendar == null)
            {
                return(response);
            }

            var result = await RequestAccess(EKEntityType.Event);

            if (result.granted)
            {
                var evt = CalendarEvent.EventStore.EventFromIdentifier(calEvent.Id);
                if (evt != null)
                {
                    evt.StartDate = calEvent.StartTime.ToNSDate();
                    evt.EndDate   = calEvent.EndTime.ToNSDate();
                    evt.Title     = calEvent.Title;
                    evt.Location  = calEvent.Location;
                    evt.Notes     = calEvent.Description;
                    evt.Calendar  = CalendarEvent.EventStore.GetCalendar(calEvent.DeviceCalendar.Id);

                    if (calEvent.HasReminder)
                    {
                        foreach (var alarm in evt.Alarms)
                        {
                            evt.RemoveAlarm(alarm);
                        }

                        var offset = calEvent.StartTime.AddMinutes(-calEvent.ReminderMinutes).ToNSDate();
                        evt.AddAlarm(EKAlarm.FromDate(offset));
                    }
                    NSError e = null;

                    var x = CalendarEvent.EventStore.SaveEvent(evt, EKSpan.ThisEvent, true, out e);

                    if (e == null)
                    {
                        response.result   = true;
                        response.model.Id = evt.EventIdentifier;
                    }
                }
            }
            return(response);
        }
Esempio n. 15
0
        private void agregaEventoaCalendario()
        {
            NSPredicate query = App.Current.EventStore.PredicateForEvents(funciones.ConvertDateTimeToNSDate(fechainicio), funciones.ConvertDateTimeToNSDate(fechafin), null);

            EKCalendarItem[] events = App.Current.EventStore.EventsMatching(query);

            if (events != null)
            {
                foreach (EKCalendarItem ev in events)
                {
                    if (ev.Title.Equals(titulo))
                    {
                        funciones.MessageBox("Error", "Ya tiene un evento con este titulo y a esa hora en su calendario");
                        return;
                    }
                }
            }


            EKEvent newEvent = EKEvent.FromStore(App.Current.EventStore);

            // set the alarm for 10 minutes from now
            DateTime fechaalarma = fechainicio.AddMinutes(-10);

            newEvent.AddAlarm(EKAlarm.FromDate(funciones.ConvertDateTimeToNSDate(fechaalarma)));
            // make the event start 20 minutes from now and last 30 minutes
            newEvent.StartDate = funciones.ConvertDateTimeToNSDate(fechainicio);
            newEvent.EndDate   = funciones.ConvertDateTimeToNSDate(fechafin);
            newEvent.Title     = titulo;
            newEvent.Notes     = notas;
            newEvent.Calendar  = App.Current.EventStore.DefaultCalendarForNewEvents;

            NSError e;

            App.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);

            if (e != null)
            {
                funciones.MessageBox("Error al guardar el evento", e.ToString());
                return;
            }
            else
            {
                funciones.MessageBox("Evento guardado", "Se ha guardado el evento en tu calendario!!");
            }
        }
Esempio n. 16
0
        private void GenerarEvento()
        {
            RequestAccess(EKEntityType.Event, () =>
            {
                CLLocation location = new CLLocation();
                if (SucursalModel.Sucursal_Id == "1")
                {
                    location = new CLLocation(20.6766, -103.3812);
                }
                else
                {
                    location = new CLLocation(20.6766, -103.3812);
                }
                var structuredLocation         = new EKStructuredLocation();
                structuredLocation.Title       = SucursalModel.Sucursal_Domicilio;
                structuredLocation.GeoLocation = location;

                NSDateFormatter dateFormat = new NSDateFormatter();
                dateFormat.DateFormat      = "E, d MMM yyyy HH:mm";
                NSDate newFormatDate       = dateFormat.Parse(this.FechaReservacion);
                EKEvent newEvent           = EKEvent.FromStore(AppHelper.Current.EventStore);

                DateTime myDate      = ((DateTime)newFormatDate).ToLocalTime();
                var HoraAntesReunion = myDate.AddHours(1 * -1);
                newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(HoraAntesReunion.AddMinutes(30))));
                newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(HoraAntesReunion.AddMinutes(45))));
                if (myDate != null)
                {
                    newEvent.StartDate = DateTimeToNSDate(myDate);
                    newEvent.EndDate   = DateTimeToNSDate(myDate.AddHours(1));
                }
                newEvent.Title = "Visita de invitados en " + SucursalModel.Sucursal_Descripcion;
                newEvent.Notes = "Invitados: ";
                foreach (UsuarioModel Invitado in InvitadosCalendar)
                {
                    newEvent.Notes = newEvent.Notes + Invitado.Usuario_Nombre + " " + Invitado.Usuario_Apellidos + ". ";
                }
                newEvent.Notes              = newEvent.Notes + " Asunto: " + Asunto;
                newEvent.Calendar           = AppHelper.Current.EventStore.DefaultCalendarForNewEvents;
                newEvent.Location           = SucursalModel.Sucursal_Domicilio;
                newEvent.StructuredLocation = structuredLocation;
                NSError e;
                AppHelper.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
            });
        }
Esempio n. 17
0
        private EKAlarm ConvertReminder(AppointmentReminder reminder, DateTime startTime)
        {
            switch (reminder)
            {
            case AppointmentReminder.none:
                return(EKAlarm.FromDate((NSDate)startTime));    ///todo should this be null?

            case AppointmentReminder.five:
                return(EKAlarm.FromDate((NSDate)startTime.AddMinutes(-5)));

            case AppointmentReminder.fifteen:
                return(EKAlarm.FromDate((NSDate)startTime.AddMinutes(-15)));

            case AppointmentReminder.thirty:
                return(EKAlarm.FromDate((NSDate)startTime.AddMinutes(-30)));
            }
            return(EKAlarm.FromDate((NSDate)startTime));
        }
        public void CreateCalendarEntry(LocalCalendarEvent localCalendarEvent)
        {
            eventStore.RequestAccess(EKEntityType.Event,
                                     (bool granted, NSError e) => {
                if (granted)
                {
                    UIApplication.SharedApplication.InvokeOnMainThread(() => {
                        EventKitUI.EKEventEditViewController eventController = new EventKitUI.EKEventEditViewController();

                        eventController.EventStore = eventStore;

                        // wire up a delegate to handle events from the controller
                        var eventControllerDelegate      = new CreateEventEditViewDelegate(eventController, eventStore);
                        eventController.EditViewDelegate = eventControllerDelegate;

                        EKEvent newEvent = EKEvent.FromStore(eventStore);

                        newEvent.StartDate = (NSDate)(DateTime.SpecifyKind(localCalendarEvent.StartDate, DateTimeKind.Local));
                        if (localCalendarEvent.EndDate.HasValue)
                        {
                            newEvent.EndDate = (NSDate)(DateTime.SpecifyKind(localCalendarEvent.EndDate.Value, DateTimeKind.Local));
                        }

                        newEvent.Title    = localCalendarEvent.Subject;
                        newEvent.Notes    = localCalendarEvent.Description;
                        newEvent.Location = localCalendarEvent.Location;

                        if (localCalendarEvent.ReminderDate.HasValue)
                        {
                            newEvent.AddAlarm(EKAlarm.FromDate((NSDate)(DateTime.SpecifyKind(localCalendarEvent.ReminderDate.Value, DateTimeKind.Local))));
                        }

                        eventController.Event = newEvent;

                        // show the event controller
                        UIApplication.SharedApplication.Windows[0].RootViewController.PresentViewController(eventController, true, null);
                    });
                }
                else
                {
                    new UIAlertView("Access Denied", "User Denied Access to Calendar Data", null, "ok", null).Show();
                }
            });
        }
Esempio n. 19
0
        /// <summary>
        /// Adds an event reminder to specified calendar event
        /// </summary>
        /// <param name="calendarEvent">Event to add the reminder to</param>
        /// <param name="reminder">The reminder</param>
        /// <returns>If successful</returns>
        /// <exception cref="ArgumentException">Calendar event is not created or not valid</exception>
        /// <exception cref="System.InvalidOperationException">Editing recurring events is not supported</exception>
        /// <exception cref="Plugin.Calendars.Abstractions.PlatformException">Unexpected platform-specific error</exception>
        public async Task <bool> AddEventReminderAsync(CalendarEvent calendarEvent, CalendarEventReminder reminder)
        {
            if (string.IsNullOrEmpty(calendarEvent.ExternalID))
            {
                throw new ArgumentException("Missing calendar event identifier", nameof(calendarEvent));
            }

            await RequestCalendarAccess().ConfigureAwait(false);

            //Grab current event
            var existingEvent = _eventStore.EventFromIdentifier(calendarEvent.ExternalID);

            if (existingEvent == null)
            {
                throw new ArgumentException("Specified calendar event not found on device");
            }

            if (existingEvent.HasRecurrenceRules)
            {
                throw new InvalidOperationException("Editing recurring events is not supported");
            }

            var seconds = -reminder?.TimeBefore.TotalSeconds ?? _defaultTimeBefore;
            var alarm   = EKAlarm.FromTimeInterval(seconds);

            existingEvent.AddAlarm(alarm);

            NSError error = null;

            if (!_eventStore.SaveEvent(existingEvent, EKSpan.ThisEvent, out error))
            {
                // Without this, the eventStore will continue to return the "updated"
                // event even though the save failed!
                // (this obviously also resets any other changes, but since we own the eventStore
                //  we can be pretty confident that won't be an issue)
                //
                _eventStore.Reset();

                throw new ArgumentException(error.LocalizedDescription, nameof(reminder), new NSErrorException(error));
            }

            return(true);
        }
Esempio n. 20
0
        public void CreateCalendarEvent(CalendarEventModel calEvent)
        {
            if (CalendarEvent.eventStore == null)
            {
                CalendarEvent.eventStore = new EKEventStore();
            }

            RequestAccess(EKEntityType.Event, () =>
            {
                EKEvent newEvent = EKEvent.FromStore(CalendarEvent.eventStore);

                if (calEvent.HasReminder)
                {
                    newEvent.AddAlarm(EKAlarm.FromDate(ToNSDate(calEvent.StartTime.AddHours(-1))));
                }

                newEvent.StartDate = ToNSDate(calEvent.StartTime);
                newEvent.EndDate   = ToNSDate(calEvent.EndTime);
                newEvent.Title     = calEvent.Title;
                newEvent.Notes     = calEvent.Description;
                newEvent.Calendar  = CalendarEvent.eventStore.DefaultCalendarForNewEvents;

                NSError e;
                CalendarEvent.eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
                if (e != null)
                {
                    new UIAlertView("Error Saving Event", e.ToString(), null, "ok", null).Show();
                    return;
                }
                else
                {
                    new UIAlertView("Event Saved", "Event ID: " + newEvent.EventIdentifier, null, "ok", null).Show();
                    Console.WriteLine("Event Saved, ID: " + newEvent.EventIdentifier);
                }

                // to retrieve the event you can call
                EKEvent mySavedEvent = CalendarEvent.eventStore.EventFromIdentifier(newEvent.EventIdentifier);
                Console.WriteLine("Retrieved Saved Event: " + mySavedEvent.Title);
            });
        }
Esempio n. 21
0
        public async Task <(bool result, CalendarEventModel model)> CreateCalendarEvent(CalendarEventModel calEvent)
        {
            (bool result, CalendarEventModel model)response = (false, calEvent);

            var result = await RequestAccess(EKEntityType.Event);

            if (result.granted)
            {
                var newEvent         = EKEvent.FromStore(CalendarEvent.EventStore);
                var selectedCalendar = CalendarEvent.EventStore.DefaultCalendarForNewEvents;
                if (calEvent.DeviceCalendar != null)
                {
                    selectedCalendar = CalendarEvent.EventStore.GetCalendar(calEvent.DeviceCalendar.Id);
                }

                newEvent.StartDate = calEvent.StartTime.ToNSDate();
                newEvent.EndDate   = calEvent.EndTime.ToNSDate();
                newEvent.Title     = calEvent.Title;
                newEvent.Notes     = calEvent.Description;
                newEvent.Calendar  = selectedCalendar;

                if (calEvent.HasReminder)
                {
                    var offset = calEvent.StartTime.AddMinutes(-calEvent.ReminderMinutes).ToNSDate();
                    newEvent.AddAlarm(EKAlarm.FromDate(offset));
                }

                NSError e;

                CalendarEvent.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, true, out e);

                if (e == null)
                {
                    response.result   = true;
                    response.model.Id = newEvent.EventIdentifier;
                }
            }

            return(response);
        }
Esempio n. 22
0
        public string AddEvent(string Title, string Description, DateTime StartDate, DateTime EndDate, string StartTimeZone, string EndTimeZone)
        {
            try
            {
                EKEvent newEvent = EKEvent.FromStore(AppMain.Self.EventStore);
                // set the alarm for 10 minutes from now
                newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(StartDate.AddMinutes(10))));
                // make the event start 20 minutes from now and last 30 minutes
                newEvent.StartDate = DateTimeToNSDate(StartDate.AddMinutes(20));
                newEvent.EndDate   = DateTimeToNSDate(EndDate.AddMinutes(50));
                newEvent.Title     = Title;
                newEvent.Notes     = Description;

                EKCalendar[] calendars = AppMain.Self.EventStore.GetCalendars(EKEntityType.Event);
                if (calendars.Length > 0)
                {
                    newEvent.Calendar = calendars.FirstOrDefault();
                }
                else
                {
                    newEvent.Calendar = AppMain.Self.EventStore.DefaultCalendarForNewEvents;
                }

                //saving the event
                NSError errorEvent;
                AppMain.Self.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out errorEvent);

                if (errorEvent != null)
                {
                    throw new Exception(errorEvent.ToString());
                }


                return("event added: " + newEvent.CalendarItemIdentifier);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 23
0
        public async Task AddReminder(string title, string notes, DateTime date)
        {
            try
            {
                var result = await _eventStore.RequestAccessAsync(EKEntityType.Reminder);

                if (result.Item1)
                {
                    EKReminder reminder = null;
                    var        predicat = _eventStore.PredicateForReminders(null);

                    var reminders = await _eventStore.FetchRemindersAsync(predicat);

                    reminder = reminders.Where((EKReminder arg) => !arg.Completed && arg.Title == title).FirstOrDefault();

                    if (reminder == null)
                    {
                        reminder = EKReminder.Create(_eventStore);
                    }

                    reminder.Title = title;
                    EKAlarm timeToRing = new EKAlarm();
                    timeToRing.AbsoluteDate = ConvertDateTimeToNSDate(date);
                    reminder.AddAlarm(timeToRing);
                    reminder.Calendar = _eventStore.DefaultCalendarForNewReminders;
                    reminder.Notes    = notes;
                    NSError error;
                    _eventStore.SaveReminder(reminder, true, out error);

                    if (error != null)
                    {
                        Debug.WriteLine(error.Description);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 24
0
        private void AddEvent(string title, string addInfo, DateTime startDate, DateTime alertDate)
        {
            var newEvent = EKEvent.FromStore(EventStore);

            newEvent.AddAlarm(EKAlarm.FromDate(alertDate.LocalDateTimeToNSDate()));
            newEvent.StartDate = startDate.LocalDateTimeToNSDate();
            newEvent.EndDate   = startDate.AddHours(1).LocalDateTimeToNSDate();
            newEvent.Title     = title;
            newEvent.Notes     = addInfo;
            newEvent.Calendar  = EventStore.DefaultCalendarForNewEvents;
            NSError err;

            EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out err);
            if (err != null)
            {
                _logger.LogMessage("Err Saving Event : " + err);
            }
            else
            {
                _logger.LogMessage("Event Saved,  ID: " + newEvent.EventIdentifier);
            }
        }
Esempio n. 25
0
    private void createAlarmForEvents()
    {
        EKEvent currentEvent;

        eventsList = PersonalXT.GetEventsFromTo(DateTime.Today, DateTime.Today.AddMonths(1));         // 30 days
        if (eventsList == null)
        {
            Log("No Events detected within 30 days");
        }
        else
        {
            foreach (object obj in eventsList)
            {
                currentEvent = obj as EKEvent;
                EKAlarm testAlarm = new EKAlarm();
                testAlarm.absoluteDate = currentEvent.startDate;
                currentEvent.AddAlarm(testAlarm);
                PersonalXT.eventStore.SaveEvent(currentEvent, EKSpan.ThisEvent, null);
                Log("Adding alert to event named: " + currentEvent.title);
            }
        }
    }
Esempio n. 26
0
        public void CreateCalendarEvent(CalendarEventModel calEvent, Action <bool> callback)
        {
            if (CalendarEvent.eventStore == null)
            {
                CalendarEvent.eventStore = new EKEventStore();
            }

            RequestAccess(EKEntityType.Event, () =>
            {
                EKEvent newEvent = EKEvent.FromStore(CalendarEvent.eventStore);

                if (calEvent.HasReminder)
                {
                    newEvent.AddAlarm(EKAlarm.FromDate(ToNSDate(calEvent.StartTime.AddHours(-1))));
                }

                newEvent.StartDate = ToNSDate(calEvent.StartTime);
                newEvent.EndDate   = ToNSDate(calEvent.EndTime);
                newEvent.Title     = calEvent.Title;
                newEvent.Notes     = calEvent.Description;
                newEvent.Calendar  = CalendarEvent.eventStore.DefaultCalendarForNewEvents;

                NSError e;
                CalendarEvent.eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
                if (e != null)
                {
                    callback?.Invoke(false);
                }
                else
                {
                    callback?.Invoke(true);
                }

                // to retrieve the event you can call
                EKEvent mySavedEvent = CalendarEvent.eventStore.EventFromIdentifier(newEvent.EventIdentifier);
                Console.WriteLine("Retrieved Saved Event: " + mySavedEvent.Title);
            });
        }
Esempio n. 27
0
        /// <summary>
        /// This method illustrates how to save and retrieve events programmatically.
        /// </summary>
        protected void SaveAndRetrieveEvent()
        {
            EKEvent newEvent = EKEvent.FromStore(App.Current.EventStore);

            // set the alarm for 5 minutes from now
            newEvent.AddAlarm(EKAlarm.FromDate(DateTime.Now.AddMinutes(5)));
            // make the event start 10 minutes from now and last 30 minutes
            newEvent.StartDate = DateTime.Now.AddMinutes(10);
            newEvent.EndDate   = DateTime.Now.AddMinutes(40);
            newEvent.Title     = "Appt. to do something Awesome!";
            newEvent.Notes     = "Find a boulder, climb it. Find a river, swim it. Find an ocean, dive it.";
            newEvent.Calendar  = App.Current.EventStore.DefaultCalendarForNewEvents;

            // save the event
            NSError e;

            App.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
            if (e != null)
            {
                new UIAlertView("Err Saving Event", e.ToString(), null, "ok", null).Show();
                return;
            }
            else
            {
                new UIAlertView("Event Saved", "Event ID: " + newEvent.EventIdentifier, null, "ok", null).Show();
                Console.WriteLine("Event Saved, ID: " + newEvent.EventIdentifier);
            }

            // to retrieve the event you can call
            EKEvent mySavedEvent = App.Current.EventStore.EventFromIdentifier(newEvent.EventIdentifier);

            Console.WriteLine("Retrieved Saved Event: " + mySavedEvent.Title);

            // to delete, note that once you remove the event, the reference will be null, so
            // if you try to access it you'll get a null reference error.
            App.Current.EventStore.RemoveEvent(mySavedEvent, EKSpan.ThisEvent, true, out e);
            Console.WriteLine("Event Deleted.");
        }
Esempio n. 28
0
        /// <summary>
        /// Adds an event reminder to specified calendar event
        /// </summary>
        /// <param name="calendarEvent">Event to add the reminder to</param>
        /// <param name="reminder">The reminder</param>
        /// <returns>Success or failure</returns>
        /// <exception cref="ArgumentException">If calendar event is not created or not valid</exception>
        /// <exception cref="Calendars.Plugin.Abstractions.PlatformException">Unexpected platform-specific error</exception>
        public Task <bool> AddEventReminderAsync(CalendarEvent calendarEvent, CalendarEventReminder reminder)
        {
            if (string.IsNullOrEmpty(calendarEvent.ExternalID))
            {
                throw new ArgumentException("Missing calendar event identifier", "calendarEvent");
            }

            //Grab current event
            var existingEvent = _eventStore.EventFromIdentifier(calendarEvent.ExternalID);

            if (existingEvent == null)
            {
                throw new ArgumentException("Specified calendar event not found on device");
            }

            //
            var seconds = -reminder?.TimeBefore.TotalSeconds ?? defaultTimeBefore;
            var alarm   = EKAlarm.FromTimeInterval(seconds);

            existingEvent.AddAlarm(alarm);
            NSError error = null;

            if (!_eventStore.SaveEvent(existingEvent, EKSpan.ThisEvent, out error))
            {
                // Without this, the eventStore will continue to return the "updated"
                // event even though the save failed!
                // (this obviously also resets any other changes, but since we own the eventStore
                //  we can be pretty confident that won't be an issue)
                //
                _eventStore.Reset();


                throw new ArgumentException(error.LocalizedDescription, "reminder", new NSErrorException(error));
            }


            return(Task.FromResult(true));
        }
Esempio n. 29
0
        /// <summary>
        /// This method illustrates how to save and retrieve events programmatically.
        /// </summary>
        private void SaveAndRetrieveEvent()
        {
            var newEvent = EKEvent.FromStore(EventStore);

            // set the alarm for 5 minutes from now
            newEvent.AddAlarm(EKAlarm.FromDate((NSDate)DateTime.Now.AddMinutes(5)));
            // make the event start 10 minutes from now and last 30 minutes
            newEvent.StartDate = (NSDate)DateTime.Now.AddMinutes(10);
            newEvent.EndDate   = (NSDate)DateTime.Now.AddMinutes(40);
            newEvent.Title     = "Appt. to do something Awesome!";
            newEvent.Notes     = "Find a boulder, climb it. Find a river, swim it. Find an ocean, dive it.";
            newEvent.Calendar  = EventStore.DefaultCalendarForNewEvents;

            // save the event
            EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out NSError error);
            if (error != null)
            {
                var alert = UIAlertController.Create("Error", error.ToString(), UIAlertControllerStyle.Alert);
                alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                base.PresentViewController(alert, true, null);
            }
            else
            {
                var alert = UIAlertController.Create("Event Saved", $"Event ID: {newEvent.EventIdentifier}", UIAlertControllerStyle.Alert);
                alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                base.PresentViewController(alert, true, null);

                // to retrieve the event you can call
                var savedEvent = EventStore.EventFromIdentifier(newEvent.EventIdentifier);
                Console.WriteLine($"Retrieved Saved Event: {savedEvent.Title}");

                // to delete, note that once you remove the event, the reference will be null, so
                // if you try to access it you'll get a null reference error.
                EventStore.RemoveEvent(savedEvent, EKSpan.ThisEvent, true, out error);
                Console.WriteLine("Event Deleted.");
            }
        }
Esempio n. 30
0
        public void SaveAndRetrieveEvent(string Title, string Desc, string Date, string Time, string location, int reservation_id)
        {
            try{
                EKEvent newEvent = EKEvent.FromStore(Apps.Current.EventStore);
                // set the alarm for 5 minutes from now
                newEvent.AddAlarm(EKAlarm.FromDate(ConvertDateTimeToNSDate(Date, Time, -120)));
                // make the event start 10 minutes from now and last 30 minutes
                newEvent.StartDate = (ConvertDateTimeToNSDate(Date, Time, 0));
                newEvent.EndDate   = (ConvertDateTimeToNSDate(Date, Time, 120));
                newEvent.Title     = Title;
                newEvent.Notes     = Desc;
                newEvent.Location  = location;
                newEvent.Calendar  = Apps.Current.EventStore.DefaultCalendarForNewEvents;

                // save the event
                NSError e;
                Apps.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
                if (e != null)
                {
                    //new UIAlertView ("Err Saving Event", e.ToString (), null, "ok", null).Show ();
                    return;
                }
                else
                {
                    //new UIAlertView ("Event Saved", "Event ID: " + newEvent.EventIdentifier, null, "ok", null).Show ();
                    Console.WriteLine("Event Saved, ID: " + newEvent.EventIdentifier);
                }

                App.Database.saveCalendar(reservation_id, newEvent.EventIdentifier.ToString(), Date);
                var calendar = App.Database.getCalendar("-1");
            }
            catch (Exception ex)
            {
                Services.Logs.Insights.Send("GetDateTimeMS", ex);
            }
        }
Esempio n. 31
0
 private void createAlarmForEvents()
 {
     EKEvent currentEvent;
     eventsList = PersonalXT.GetEventsFromTo(DateTime.Today, DateTime.Today.AddMonths(1)); // 30 days
     if(eventsList == null )
     {
         Log ("No Events detected within 30 days");
     }
     else
     {
         foreach (object obj in eventsList){
             currentEvent = obj as EKEvent;
             EKAlarm testAlarm = new EKAlarm();
             testAlarm.absoluteDate = currentEvent.startDate;
             currentEvent.AddAlarm(testAlarm);
             PersonalXT.eventStore.SaveEvent(currentEvent,EKSpan.ThisEvent, null);
             Log ("Adding alert to event named: " + currentEvent.title);
         }
     }
 }
Esempio n. 32
0
        /// <summary>
        /// Launchs the create new event controller.
        /// </summary>
        protected void LaunchCreateNewEvent(CalendarEntry entry)
        {
            EKEventStore store = IPhoneServiceLocator.CurrentDelegate.EventStore;
            EKCalendar calendar = store.DefaultCalendarForNewEvents;

            EKEvent calendarEvent = EKEvent.FromStore(store);
            // add event to the default calendar for the new events
            calendarEvent.Calendar = calendar;

            try {
                // add event details
                calendarEvent.Title = entry.Title;
                if(entry.Notes == null) {
                    entry.Notes = "";
                }
                calendarEvent.Notes = entry.Notes;
                calendarEvent.Location = entry.Location;
                calendarEvent.AllDay = entry.IsAllDayEvent;
                calendarEvent.StartDate = IPhoneUtils.DateTimeToNSDate(entry.StartDate);
                calendarEvent.EndDate = IPhoneUtils.DateTimeToNSDate(entry.EndDate);

                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Creating Calendar Event: " + calendarEvent.Title);
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Default Calendar: " + calendar.Title);
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Event StartDate: " + calendarEvent.StartDate.ToString());
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Event EndDate: " + calendarEvent.EndDate.ToString());
                // TODO: locate how to translate this features
                // entry.Type (birthday, exchange, etc)
                //calendarEvent.  = entry.IsEditable

                // Attendees
                if(entry.Attendees != null && entry.Attendees.Length >0) {
                    int attendeesNum = entry.Attendees.Length;
                    // TODO : check another way to add participants
                    // calendarEvent.Attendees --> READ ONLY !!!
                }

                // Alarms
                if(entry.Alarms != null && entry.Alarms.Length >0) {
                    foreach(CalendarAlarm alarm in entry.Alarms) {
                        EKAlarm eventAlarm = new EKAlarm();
                        eventAlarm.AbsoluteDate = IPhoneUtils.DateTimeToNSDate(alarm.Trigger);
                        // TODO: how to manage "action", "sound" and "emailaddress"
                        calendarEvent.AddAlarm(eventAlarm);
                    }
                }

                if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0)) {
                    // Recurrence Rules
                    if(entry.IsRecurrentEvent && entry.Recurrence != null) {
                        EKRecurrenceFrequency recurrenceFrequency = EKRecurrenceFrequency.Daily;
                        if(entry.Recurrence.Type == RecurrenceType.Weekly) {
                            recurrenceFrequency = EKRecurrenceFrequency.Weekly;
                        } else if(entry.Recurrence.Type == RecurrenceType.Montly) {
                            recurrenceFrequency = EKRecurrenceFrequency.Monthly;
                        } else if(entry.Recurrence.Type == RecurrenceType.Yearly) {
                            recurrenceFrequency = EKRecurrenceFrequency.Yearly;
                        } else if(entry.Recurrence.Type == RecurrenceType.FourWeekly) {
                            recurrenceFrequency = EKRecurrenceFrequency.Weekly;
                            entry.Recurrence.Interval = 4; // force event to be repeated "every 4 weeks"
                        } else if(entry.Recurrence.Type == RecurrenceType.Fortnightly) {
                            recurrenceFrequency = EKRecurrenceFrequency.Weekly;
                            entry.Recurrence.Interval = 2; // force event to be repeated "every 2 weeks"
                        }
                        EKRecurrenceEnd recurrenceEnd = null;
                        SystemLogger.Log(SystemLogger.Module.PLATFORM, "Recurrence Frequency: " + recurrenceFrequency);
                        SystemLogger.Log(SystemLogger.Module.PLATFORM, "Recurrence Interval: " + entry.Recurrence.Interval);
                        SystemLogger.Log(SystemLogger.Module.PLATFORM, "Recurrence EndDate (requested): " + entry.Recurrence.EndDate.ToString());
                        SystemLogger.Log(SystemLogger.Module.PLATFORM, "Recurrence number: " + entry.RecurrenceNumber);
                        if(entry.Recurrence.EndDate.CompareTo(entry.EndDate)>0) {
                            recurrenceEnd = EKRecurrenceEnd.FromEndDate(IPhoneUtils.DateTimeToNSDate(entry.Recurrence.EndDate));
                            SystemLogger.Log(SystemLogger.Module.PLATFORM, "Recurrence EndDate (applied): " + recurrenceEnd.EndDate.ToString());
                        } else if(entry.RecurrenceNumber > 0) {
                            recurrenceEnd = EKRecurrenceEnd.FromOccurrenceCount((int)entry.RecurrenceNumber);
                            SystemLogger.Log(SystemLogger.Module.PLATFORM, "Recurrence OcurrenceCount: " + recurrenceEnd.OccurrenceCount);
                        } else {
                            recurrenceEnd = new EKRecurrenceEnd();
                        }
                        EKRecurrenceRule recurrenceRule = new EKRecurrenceRule(recurrenceFrequency,entry.Recurrence.Interval, recurrenceEnd);
                        if(entry.Recurrence.DayOfTheWeek > 0) {
                            EKRecurrenceDayOfWeek dayOfWeek = EKRecurrenceDayOfWeek.FromWeekDay(entry.Recurrence.DayOfTheWeek,0);
                            EKRecurrenceDayOfWeek[] arrayDayOfWeek = new EKRecurrenceDayOfWeek[1];
                            arrayDayOfWeek[0] = dayOfWeek;
                            SystemLogger.Log(SystemLogger.Module.PLATFORM, "Setting DayOfTheWeek: " + dayOfWeek.DayOfTheWeek);
                            recurrenceRule = new EKRecurrenceRule(recurrenceFrequency,entry.Recurrence.Interval, arrayDayOfWeek, null, null, null, null, null, recurrenceEnd);
                        }

                        calendarEvent.AddRecurrenceRule(recurrenceRule);
                    }
                }
            } catch (Exception e) {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "ERROR Creating Calendar Event [" + calendarEvent.Title + "]. Error message: " + e.Message);
            }

            EKEventEditViewController eventViewController = new EKEventEditViewController();
            eventViewController.Event = calendarEvent;
            eventViewController.EventStore = store;
            eventViewController.Completed += delegate(object sender, EKEventEditEventArgs e) {
                UIApplication.SharedApplication.InvokeOnMainThread (delegate {
                    SystemLogger.Log(SystemLogger.Module.PLATFORM, "On EKEventEditViewController Completed: " + e.Action);
                    if(e.Action == EKEventEditViewAction.Saved) {
                        INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance ().GetService ("notify");
                        if (notificationService != null) {
                            notificationService.StartNotifyAlert ("Calendar Alert", "Calendar Entry Saved", "OK");
                        }
                    }
                    IPhoneServiceLocator.CurrentDelegate.MainUIViewController ().DismissModalViewController(true);
                });
            };

            IPhoneServiceLocator.CurrentDelegate.MainUIViewController ().PresentModalViewController (eventViewController, true);
            IPhoneServiceLocator.CurrentDelegate.SetMainUIViewControllerAsTopController(false);
        }