public Task <CalendarEventViewModel[]> Handle(
            GetAllCalendarEventsQuery request,
            CancellationToken cancellationToken)
        {
            var calendarEvents = _repository.List()
                                 .Select(calendarEvent =>
                                         new CalendarEventViewModel(
                                             calendarEvent.Id,
                                             calendarEvent.Name,
                                             calendarEvent.Time,
                                             calendarEvent.Location,
                                             calendarEvent.Organizer,
                                             calendarEvent.Members.Select(m => m.Name).ToArray()
                                             )
                                         ).ToArray();

            return(Task.FromResult(calendarEvents));
        }
Exemplo n.º 2
0
        public async Task <CalendarEventViewModel[]> Handle(
            GetCalendarEventsFilterQuery request,
            CancellationToken cancellationToken)
        {
            var calendarEvents = _repository.List();
            var filters        = request.CalendarEventFilter;

            if (filters.EventOrganizer != null)
            {
                calendarEvents = calendarEvents.Where(ce => ce.Organizer == filters.EventOrganizer);
            }

            if (!String.IsNullOrEmpty(filters.Id))
            {
                calendarEvents = calendarEvents.Where(ce => ce.Id == filters.Id);
            }

            if (filters.Location != null)
            {
                calendarEvents = calendarEvents.Where(ce => ce.Location == filters.Location);
            }

            if (filters.Name != null)
            {
                calendarEvents = calendarEvents.Where(ce => ce.Name == filters.Name);
            }

            var calendarEventsFiltered = calendarEvents.Select(calendarEvent =>
                                                               new CalendarEventViewModel(
                                                                   calendarEvent.Id,
                                                                   calendarEvent.Name,
                                                                   calendarEvent.Time,
                                                                   calendarEvent.Location,
                                                                   calendarEvent.Organizer,
                                                                   calendarEvent.Members.Select(m => m.Name).ToArray()
                                                                   )
                                                               ).ToArray();

            return(await Task.FromResult(calendarEventsFiltered));
        }