public IActionResult InAgeRange([FromQuery] int olderThan, [FromQuery] int youngerThan) { ExpressionSpecification <UserModel> specification = new YoungerThanSpecification(youngerThan) .And(new OlderThanSpecification(olderThan)); List <UserModel> users = _userRepository.GetUsers(specification) .ToList(); if (!users.Any()) { return(StatusCode((int)HttpStatusCode.NotFound)); } return(StatusCode((int)HttpStatusCode.OK, new { totalCount = users.Count, users })); }
public IActionResult FetchWithRepository([FromQuery] int?shorterThan, [FromQuery] int?tallerThan, [FromQuery] int?olderThan, [FromQuery] int?youngerThan) { ExpressionSpecification <UserModel> specification = null; if (shorterThan.HasValue) { specification = new ShorterThanSpecification(shorterThan.Value); } if (tallerThan.HasValue) { var tallerThanSpecification = new TallerThanSpecification(tallerThan.Value); specification = specification?.And(tallerThanSpecification) ?? tallerThanSpecification; } if (youngerThan.HasValue) { var youngerThanSpecification = new YoungerThanSpecification(youngerThan.Value); specification = specification?.And(youngerThanSpecification) ?? youngerThanSpecification; } if (olderThan.HasValue) { var olderThanSpecification = new OlderThanSpecification(olderThan.Value); specification = specification?.And(olderThanSpecification) ?? olderThanSpecification; } List <UserModel> users = _userRepository.GetUsers(specification) .ToList(); if (!users.Any()) { return(StatusCode((int)HttpStatusCode.NotFound)); } return(StatusCode((int)HttpStatusCode.OK, new { totalCount = users.Count, users })); }