public IActionResult AllUserRestaurants() { List <RestaurantAndFoodsDto> listRAF = new List <RestaurantAndFoodsDto>(); byte[] identity = HttpContext.Session.Get(ProgramParameters.Identity); if (identity != null) { User user = _repository.GetUserByIdentity( new Guid(HttpContext.Session.Get(ProgramParameters.Identity))); int userId = user.Id; List <Restaurant> restaurants = _repository.GetRestaurantsByUserId(userId); foreach (Restaurant restaurant in restaurants) { RestaurantAndFoodsDto restaurantAndFoods = new RestaurantAndFoodsDto(); restaurantAndFoods.Restaurant = restaurant; List <Food> specificFood = _repository.GetFoodByRestaurantId(restaurant.Id); restaurantAndFoods.Foods = specificFood; listRAF.Add(restaurantAndFoods); } AllRestaurantsAndFoods allRestaurantsAndFoods = new AllRestaurantsAndFoods(listRAF); return(View("MyRestaurants", allRestaurantsAndFoods)); } else { return(View("Login")); } }
public IActionResult HomePage() { //ViewBag["Identified"] = Identified; // Pass this to the view and use it to render the page, knowing // if the user has authenticated. List <RestaurantAndFoodsDto> listRAF = new List <RestaurantAndFoodsDto>(); /*int userId = _repository.GetUserByIdentity( * new Guid(HttpContext.Session.Get(ProgramParameters.Identity))).Id;*/ List <Restaurant> restaurants = _repository.GetAllRestaurants(); foreach (Restaurant restaurant in restaurants) { RestaurantAndFoodsDto restaurantAndFoods = new RestaurantAndFoodsDto(); restaurantAndFoods.Restaurant = restaurant; List <Food> specificFood = _repository.GetFoodByRestaurantId(restaurant.Id); restaurantAndFoods.Foods = specificFood; listRAF.Add(restaurantAndFoods); } AllRestaurantsAndFoods allRestaurantsAndFoods = new AllRestaurantsAndFoods(listRAF); return(View("Homepage", allRestaurantsAndFoods)); }