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)); }
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))); } }
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()); }