public async Task <IActionResult> GetDetails(int eventId)
        {
            IDatabaseContext context = _getDatabaseContext();
            Event            @event  = await context.Events
                                       .Include(e => e.Organizer)
                                       .Include(e => e.EventParticipations)
                                       .ThenInclude(p => p.Participant)
                                       .FirstOrDefaultAsync(e => e.Id == eventId);

            if (@event == null)
            {
                return(NotFound());
            }

            int currentUserId = HttpContext.GetUserId();

            ViewEventInformation viewEventInformation = ViewEventInformation.FromEvent(@event, currentUserId);

            if (!viewEventInformation.CurrentUserDoesParticipate && @event.IsPrivate && (@event.OrganizerId != currentUserId))
            {
                return(BadRequest(RequestStringMessages.InvitationRequired));
            }

            List <User> allParticipants = @event.EventParticipations.Select(e => e.Participant).ToList();

            List <Appointment> appointments = await context.Appointments
                                              .Include(a => a.AppointmentParticipations)
                                              .ThenInclude(ap => ap.Participant)
                                              .Where(a => a.StartTime >= DateTime.UtcNow)
                                              .OrderBy(a => a.StartTime)
                                              .Take(_maxShownAppointmentsPerEvent)
                                              .ToListAsync();

            List <AppointmentDetails> upcomingAppointments = appointments
                                                             .Select(a => AppointmentDetails.FromAppointment(a, currentUserId, allParticipants))
                                                             .ToList();

            EventParticipation currentEventParticipation = @event.EventParticipations.FirstOrDefault(e => e.ParticipantId == currentUserId);


            NotificationConfigurationResponse notificationConfigurationResponse = null;

            if (currentEventParticipation != null)
            {
                notificationConfigurationResponse = NotificationConfigurationResponse.FromParticipation(currentEventParticipation);
            }

            return(Ok(new EventDetails(viewEventInformation, upcomingAppointments, notificationConfigurationResponse)));
        }
        public async Task <IActionResult> GetEditDetails(int eventId)
        {
            IDatabaseContext context = _getDatabaseContext();
            Event            @event  = await context.Events
                                       .Include(e => e.EventParticipations)
                                       .ThenInclude(ep => ep.Participant)
                                       .Include(e => e.Appointments)
                                       .ThenInclude(ap => ap.AppointmentParticipations)
                                       .Include(e => e.Organizer)
                                       .FirstOrDefaultAsync(e => e.Id == eventId);

            if (@event == null)
            {
                return(NotFound());
            }

            int currentUserId = HttpContext.GetUserId();

            if (@event.OrganizerId != currentUserId)
            {
                _logger.LogInformation("{0}(): Tried to edit event {1}, which he's not organizing", nameof(GetEditDetails), @event.Id);

                return(BadRequest(RequestStringMessages.OrganizerRequired));
            }

            List <User> allParticipants = @event.EventParticipations.Select(e => e.Participant).ToList();

            List <AppointmentDetails> upcomingAppointments = @event.Appointments
                                                             .Where(a => a.StartTime >= DateTime.UtcNow)
                                                             .OrderBy(a => a.StartTime)
                                                             .Select(a => AppointmentDetails.FromAppointment(a, currentUserId, allParticipants))
                                                             .ToList();

            List <EventParticipantInformation> currentEventParticipation = @event.EventParticipations.Select(EventParticipantInformation.FromParticipation).ToList();

            ViewEventInformation viewEventInformation = ViewEventInformation.FromEvent(@event, currentUserId);

            return(Ok(new EditEventDetails(viewEventInformation, upcomingAppointments, currentEventParticipation)));
        }