public JsonResult GetDishes(int?id) { if (id != null) { var meals = _db.Meals.Where(m => m.RestaurantId == id); List <MealDishResponse> response = new List <MealDishResponse>(); foreach (var meal in meals) { var dishes = _db.Dishes.Where(s => s.MealId == meal.MealId).ToList(); var _response = new MealDishResponse { meal = meal, dishes = dishes }; response.Add(_response); } return(Json(new { data = response })); } return(Json(new { })); }
public IActionResult Dashboard(int?id) { if (id != null) { var meals = _db.Meals.Where(m => m.RestaurantId == id); List <MealDishResponse> response = new List <MealDishResponse>(); var landingInfo = _db.LandingInfo.Where(l => l.Approval == ApprovalEnum.Apply); var restaurant = _db.Restaurants.Find(id); ViewData["restaurantname"] = restaurant.Name; ViewData["restaurantlogo"] = restaurant.Logo; ViewData["restaurantmotto"] = restaurant.Motto; ViewData["restaurantlocation"] = restaurant.Location; ViewData["restaurantnumber"] = restaurant.ContactNumber; ViewData["restaurantemail"] = restaurant.ContactEmail; foreach (var meal in meals) { var dishes = _db.Dishes.Where(s => s.MealId == meal.MealId).ToList(); var _response = new MealDishResponse { meal = meal, dishes = dishes }; response.Add(_response); } ViewData["dishes"] = response; return(View()); } else { return(RedirectToAction("Dashboard", "Restaurants")); } }