Exemplo n.º 1
0
        public async Task <CalendarEventModel> GetCalendarEvent(string id)
        {
            var result = await RequestAccess(EKEntityType.Event);

            if (result.granted)
            {
                var evt = CalendarEvent.EventStore.EventFromIdentifier(id);
                if (evt != null)
                {
                    var model = new CalendarEventModel()
                    {
                        Id             = evt.EventIdentifier,
                        Description    = evt.Notes,
                        HasReminder    = evt.HasAlarms,
                        Title          = evt.Title,
                        EndTime        = evt.EndDate.ToDateTime(),
                        StartTime      = evt.StartDate.ToDateTime(),
                        DeviceCalendar = new CalendarAccount()
                        {
                            Id = evt.Calendar.CalendarIdentifier
                        }
                    };
                    return(model);
                }
            }
            return(null);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }