Skip to content

Commit

Permalink
Merge pull request #83 from builttoroam/feature/81-delete-calendar-in…
Browse files Browse the repository at this point in the history
…stance-ios

#87 ios: delete calendar event instance
  • Loading branch information
ScottBTR authored Feb 6, 2020
2 parents 73a21d1 + e8fd349 commit 2d12c58
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Xamarin.Essentials/Calendars/Calendars.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,17 @@ static async Task<bool> PlatformDeleteCalendarEventInstanceByDate(string eventId
{
throw new ArgumentException("[iOS]: You must supply an event id to delete an event.");
}
var calendars = CalendarRequest.Instance.Calendars.Where(x => x.CalendarIdentifier == calendarId).ToArray();
var query = CalendarRequest.Instance.PredicateForEvents(dateOfInstanceUtc.ToNSDate(), dateOfInstanceUtc.AddDays(1).ToNSDate(), calendars);
var events = CalendarRequest.Instance.EventsMatching(query);
var thisEvent = events.FirstOrDefault(x => x.CalendarItemIdentifier == eventId);

var calendarEvent = CalendarRequest.Instance.GetCalendarItem(eventId) as EKEvent;

if (calendarEvent.Calendar.CalendarIdentifier != calendarId)
if ((thisEvent?.Calendar.CalendarIdentifier ?? string.Empty) != calendarId)
{
throw new ArgumentOutOfRangeException("[iOS]: Supplied event does not belong to supplied calendar.");
}

if (CalendarRequest.Instance.RemoveEvent(calendarEvent, EKSpan.ThisEvent, true, out var error))
if (CalendarRequest.Instance.RemoveEvent(thisEvent, EKSpan.ThisEvent, true, out var error))
{
return true;
}
Expand All @@ -444,7 +446,7 @@ static async Task<bool> PlatformDeleteCalendarEventById(string eventId, string c

var calendarEvent = CalendarRequest.Instance.GetCalendarItem(eventId) as EKEvent;

if (calendarEvent.Calendar.CalendarIdentifier != calendarId)
if ((calendarEvent?.Calendar.CalendarIdentifier ?? string.Empty) != calendarId)
{
throw new ArgumentOutOfRangeException("[iOS]: Supplied event does not belong to supplied calendar.");
}
Expand All @@ -462,7 +464,7 @@ static async Task<string> PlatformCreateCalendar(Calendar newCalendar)

var calendar = EKCalendar.Create(EKEntityType.Event, CalendarRequest.Instance);
calendar.Title = newCalendar.Name;
var source = CalendarRequest.Instance.Sources.Where(x => x.SourceType == EKSourceType.Local).FirstOrDefault();
var source = CalendarRequest.Instance.Sources.FirstOrDefault(x => x.SourceType == EKSourceType.Local);
calendar.Source = source;

if (CalendarRequest.Instance.SaveCalendar(calendar, true, out var error))
Expand Down

0 comments on commit 2d12c58

Please sign in to comment.