private IQueryable <Match> GetMatcesIQueryable(MatchFilterDto filter) { IQueryable <Match> matches = _db.Matches; if (filter.DateFrom.HasValue) { matches = matches.Where(x => x.KickoffAt > filter.DateFrom); } if (filter.DateTo.HasValue) { matches = matches.Where(x => x.KickoffAt < filter.DateTo); } if (filter.Group?.Length > 0) { matches = matches.Where(x => filter.Group.Select(s => s.ToLowerInvariant()).Contains(x.Group.ToLowerInvariant())); } if (filter.Team?.Length > 0) { matches = matches.Where(x => filter.Team .Select(s => s.ToLowerInvariant()).Contains(x.HomeTeam.ToLowerInvariant()) || filter.Team .Select(s => s.ToLowerInvariant()).Contains(x.AwayTeam.ToLowerInvariant()) ); } return(matches); }
public void TestGetMatches_WithEmptyFilter() { _applicationContext.Database.EnsureDeleted(); _applicationContext.Matches.AddRange(this.matches); _applicationContext.SaveChanges(); var filter = new MatchFilterDto(); var matches = _matchService.GetMatches(filter); Assert.AreEqual(4, matches.Count); }
public void TestGetMatches_WithFilter() { _applicationContext.Database.EnsureDeleted(); _applicationContext.Matches.AddRange(this.matches); _applicationContext.SaveChanges(); var filter = new MatchFilterDto { DateFrom = DateTime.Now.AddDays(-3), DateTo = DateTime.Now.AddDays(1), Group = new string[] { "A" }, Team = new string[] { "Team 1", "Team 2" } }; var matches = _matchService.GetMatches(filter); Assert.AreEqual(2, matches.Count); }
public IActionResult GetMatches(MatchFilterDto filter) { var result = _matchService.GetMatches(filter); return(result != null ? (IActionResult)Ok(result) : BadRequest()); }
public List <MatchDto> GetMatches(MatchFilterDto filter) { var matches = GetMatcesIQueryable(filter); return(Mapper.Map <List <MatchDto> >(matches)); }