public async Task <CalendarEvent> CreateAsync(CalendarEvent calendarEvent) { // Validations if (calendarEvent.Id != 0) { throw new IllegalArgumentException("IllegalAttribute", "Calender event cannot have an id on create."); } if (calendarEvent.VisitDate == null) { throw new IllegalArgumentException("IllegalAttribute", "Visit date is required on calendar event creation."); } if (calendarEvent.Period == null) { throw new IllegalArgumentException("IllegalAttribute", "Period is required on calendar event creation."); } if (calendarEvent.RequiresFromHour && calendarEvent.FromHour == null) { throw new IllegalArgumentException("IllegalAttribute", $"FromHour is required on calendar event for period {calendarEvent.Period}."); } if (calendarEvent.RequiresUntilHour && calendarEvent.UntilHour == null) { throw new IllegalArgumentException("IllegalAttribute", $"UntilHour is required on calendar event for period {calendarEvent.Period}."); } if (calendarEvent.Request == null) { throw new IllegalArgumentException("IllegalAttribute", "Request is required on calendar event creation."); } if (calendarEvent.CalendarId != null || calendarEvent.MsObjectId != null || calendarEvent.CalendarId != null) { throw new IllegalArgumentException("IllegalAttribute", "Calendar properties cannot be set."); } if (calendarEvent.Customer != null) { var message = "Customer cannot be added to a calendar event on creation."; _logger.LogDebug(message); throw new IllegalArgumentException("IllegalAttribute", message); } await EmbedRelations(calendarEvent); var customerEntity = await GetRelatedCustomerEntity(calendarEvent); calendarEvent = await _graphApiService.CreateEventForRequestAsync(calendarEvent, customerEntity); return(await _visitDataProvider.UpdateAsync(calendarEvent)); }