public IEnumerable <AdDTO> Execute(AdQuery request) { var query = Context.Ads.AsQueryable(); if (request.Title != null) { query = query.Where(a => a.Title .ToLower() .Contains( request.Title.ToLower()) ); } if (request.Body != null) { query = query.Where(b => b.Body .ToLower() .Contains( request.Body.ToLower()) ); } if (request.Price.HasValue) { query = query.Where(p => p.Price == request.Price); } if (request.IsShipping.HasValue) { query = query.Where(s => s.IsShipping == request.IsShipping); } return(query.Select(s => new AdDTO { Id = s.Id, Title = s.Title, Body = s.Body, Price = s.Price, IsShipping = s.IsShipping, CategoryId = s.Category.Id, UserId = s.User.Id })); }
public IActionResult Get([FromQuery] AdQuery query) { return(Ok(_getCommand.Execute(query))); }
// GET: Ad public ActionResult Index(AdQuery search) { var ad = _getCommand.Execute(search); return(View(ad)); }