예제 #1
0
        public async Task <IActionResult> GetEvents(EventSearchParameter searchParameter)
        {
            var result = new JsonResult <List <EventDTO> >();

            try
            {
                result.Result  = (await _service.GetEventsAsync(searchParameter)).Select(x => Mapper.Map <Event, EventDTO>(x)).ToList();
                result.Success = true;
            }
            catch
            {
                result.Message = "Váratlan hiba az események letöltése során.";
            }
            return(Ok(result));
        }
예제 #2
0
        public async Task GetEventListWithName(string nameOfEvent)
        {
            // Arrange
            using (var context = DbContextHelper.GetInMemoryDbContext())
            {
                var service         = new EventService(context);
                var searchParameter = new EventSearchParameter
                {
                    Name = nameOfEvent
                };

                // Act
                var events = await service.GetEventsAsync(searchParameter);

                // Assert
                Assert.True(!events.Any(x => !x.Name.StartsWith(nameOfEvent)));
            }
        }
예제 #3
0
        public async Task <List <Event> > GetEventsAsync(EventSearchParameter searchParameter)
        {
            IQueryable <Event> q = _ctx.Events
                                   .Include(x => x.Image)
                                   .Include(x => x.EvenSchedules)
                                   .Include(x => x.ServiceEvents);

            if (searchParameter.ServiceId.HasValue)
            {
                q = q.Where(x => x.ServiceEvents.Any(y => y.ServiceId == searchParameter.ServiceId));
            }
            if (!string.IsNullOrEmpty(searchParameter.Name))
            {
                q = q.Where(x => x.Name.Contains(searchParameter.Name));
            }
            if (searchParameter.BeginDate.HasValue)
            {
                q = q.Where(x => x.EvenSchedules.Any(y => y.From >= searchParameter.BeginDate));
            }
            return(await q.ToListAsync());
        }