public IActionResult DeleteRestaurant(int id) { var restaurantUC = new RestaurantUC(restoRepository); var resto = restaurantUC.GetRestaurantById(id); if (resto == null) { return(RedirectToAction("Error", new { errorMessage = "Sorry! We don't find the restaurant with this Id" })); } else { try { restaurantUC.DeleteRestaurant(id); } catch { throw new Exception("A problem occured..."); } if (User.IsInRole("Administrators")) { return(RedirectToAction("GetAllRestaurantsAdmin")); } else { return(RedirectToAction("GetRestaurantsByRestaurantManager")); } } }
public IActionResult RestaurantDetails(int id) { var restaurantUC = new RestaurantUC(restoRepository); var result = restaurantUC.GetRestaurantById(id); if (result != null) { return(View(result)); } else { return(RedirectToAction("Error", new { errorMessage = "Sorry! We don't find this restaurant" })); } }
public void GetRestaurantById_Should_Return_Null_When_Not_Found() { //Arrange var mock = new Mock <IRestoRepository>(); mock.Setup(x => x.GetById(25)); RestaurantUC target = new RestaurantUC(mock.Object); //Act var result = target.GetRestaurantById(25); //Assert Assert.AreEqual(null, result); Assert.IsNull(result); }
public IActionResult GetBasketsByRestoId(int restoId) { var result = basketUC.GetBasketsByRestoId(restoId).ToList(); RestaurantUC restoUC = new RestaurantUC(restoRepository); foreach (var item in result) { foreach (var shoppingMeal in item.ShoppingMeals) { shoppingMeal.Meal.MealType = mealTypeUC.GetMealTypeById(shoppingMeal.Meal.MealTypeID); shoppingMeal.Meal.MealType.Restaurant = restoUC.GetRestaurantById(shoppingMeal.Meal.MealType.RestaurantId); } } return(View(result.OrderBy(x => x.ArrivalDate).ToList())); }
public IActionResult GetBasketsByUserId() { var result = basketUC.GetBasketsByUserId(User.FindFirst(ClaimTypes.NameIdentifier).Value).ToList(); RestaurantUC restoUC = new RestaurantUC(restoRepository); foreach (var item in result) { foreach (var shoppingMeal in item.ShoppingMeals) { shoppingMeal.Meal.MealType = mealTypeUC.GetMealTypeById(shoppingMeal.Meal.MealTypeID); shoppingMeal.Meal.MealType.Restaurant = restoUC.GetRestaurantById(shoppingMeal.Meal.MealType.RestaurantId); } } result = result.OrderBy(x => x.ArrivalDate).ToList(); return(View(result)); }
public void GetRestaurantById_Should_Return_Valid_Data() { //Arrange var mock = new Mock <IRestoRepository>(); mock.Setup(x => x.GetById(1)).Returns( new RestoDTO { City = "Bruxelles", Id = 1, Name = "R1" } ); RestaurantUC target = new RestaurantUC(mock.Object); //Act var result = target.GetRestaurantById(1); //Assert Assert.AreEqual(result.Id, 1); Assert.AreEqual(result.City, "Bruxelles"); Assert.AreEqual(result.Name, "R1"); }
public IActionResult EditRestaurant(int id) { var restaurantUC = new RestaurantUC(restoRepository); var result = restaurantUC.GetRestaurantById(id); if (result.Pictures.Count == 0) { result.Pictures = new List <PictureBTO>().DefaultIfEmpty().ToList(); } result.Cuisines = cuisineUC.GetAllCuisinesByRestaurantId(result.Id).ToList(); //var cuisinesChecked = if (result != null) { return(View(result)); } else { return(RedirectToAction("Error", new { errorMessage = "Sorry! We don't find the restaurant with this Id" })); } }