Exemplo n.º 1
0
        public async Task <IReadOnlyList <Event <string, string> > > GetEventsAsync(EventsSpecification specification = null)
        {
            IQueryable <Event> query = _db.Events;

            if (specification != null)
            {
                query = query.Where(specification.GetFilterExpression());
            }

            var eventsInfo = await query.ToArrayAsync();

            var events = new List <Event <string, string> >(eventsInfo.Length);

            if (eventsInfo.Length == 0)
            {
                return(events);
            }

            var placesRepository = new PlacesRepository(_db);

            var places = await placesRepository.GetPlacesAsync();

            foreach (var eventInfo in eventsInfo)
            {
                var startDate = GetStartDate(eventInfo);
                var endDate   = GetEndDate(eventInfo);

                var @event = new Event <string, string>(eventInfo.Content, startDate, endDate)
                {
                    Id = eventInfo.Id
                };

                if (eventInfo.PlaceId != null)
                {
                    @event.Place = places.GetNodeById(eventInfo.PlaceId);
                }

                events.Add(@event);
            }

            return(events);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Reverts specification.
 /// </summary>
 /// <param name="spec">Specification.</param>
 public static EventsSpecification Not(EventsSpecification spec)
 => new NotEventsSpecification(spec);
Exemplo n.º 3
0
 /// <summary>
 /// Combines this specification with another one
 /// using AND operator.
 /// </summary>
 /// <param name="anotherSpec">Another specification.</param>
 public EventsSpecification And(EventsSpecification anotherSpec)
 => new AndEventsSpecification(this, anotherSpec);
Exemplo n.º 4
0
 /// <summary>
 /// Combines this specification with another one
 /// using OR operator.
 /// </summary>
 /// <param name="anotherSpec">Another specification.</param>
 public EventsSpecification Or(EventsSpecification anotherSpec)
 => new OrEventsSpecification(this, anotherSpec);
Exemplo n.º 5
0
 public NotEventsSpecification(EventsSpecification specification)
 {
     _specification = specification ?? throw new ArgumentNullException(nameof(specification));
 }