public async Task <List <Restaurant> > GetRestaurants(RestaurantQueryModel query) { IQueryable <Restaurant> restaurants = _context.Restaurants; if (query.City != null) { restaurants = restaurants.Where(o => o.City == query.City); } if (query.Id > 0) { restaurants = restaurants.Where(o => o.Id == query.Id); } return(await restaurants.OrderBy(o => o.Id).ToListAsync()); }
public async Task <IActionResult> GetById(int?id, string city) { var queryModel = new RestaurantQueryModel(); if (id.HasValue) { queryModel.Id = id.Value; } queryModel.City = city; var result = await _repository.GetRestaurants(queryModel); if (result == null) { return(new NotFoundResult()); } return(Ok((result))); }
public async Task <IActionResult> update(int resturentId, [FromBody] Restaurant restaurant) { var queryModel = new RestaurantQueryModel { Id = resturentId }; var result = await _repository.GetRestaurants(queryModel); if (result == null) { return(new BadRequestResult()); } var result1 = await _repository.UpdateRestaurant(restaurant); if (result1 == null) { return(new BadRequestResult()); } return(this.StatusCode(StatusCodes.Status204NoContent)); }
public async Task <IActionResult> DeleteById(int resturentId) { var queryModel = new RestaurantQueryModel { Id = resturentId }; var restaurants = await _repository.GetRestaurants(queryModel); if (restaurants == null) { return(new NotFoundResult()); } var result = await _repository.DeleteRestaurant(restaurants.FirstOrDefault()); if (result == null) { return(new NotFoundResult()); } return(this.StatusCode(StatusCodes.Status204NoContent)); }
public async Task <IActionResult> GetRestaurantByCity([FromQuery] RestaurantQueryModel query) { var result = await _restaurantService.GetRestaurantByCity(query); return(Ok(result)); }
public async Task <List <Restaurant> > GetRestaurantByCity(RestaurantQueryModel query) { return(await _repository.GetRestaurants(query)); }