Ejemplo n.º 1
0
        public IActionResult CreateBasket(DateTime arrivalDate)
        {
            basketUC = GetBasketUC();


            if (basketUC.shoppingMeals.Count() == 0)
            {
                return(RedirectToAction("Error", new { errorMessage = "Sorry, your basket is empty..." }));
            }
            if (!ModelState.IsValid)
            {
                return(View(basketUC));
            }
            var basketBTO = new BasketBTO();

            basketBTO.ArrivalDate = arrivalDate;

            RestaurantUC restoUC = new RestaurantUC(restoRepository);

            basketBTO.ShoppingMeals = basketUC.shoppingMeals
                                      .Select(x => x.ShoppingMealDomainToBTO())
                                      .ToList();

            basketBTO.UserId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? null;

            if (basketBTO.UserId == null)
            {
                return(RedirectToAction("Error", new { errorMessage = "You have to be logged to complete your order" }));
            }

            if (!restoUC.IsOpen(basketUC.restoId, basketBTO.ArrivalDate))
            {
                return(RedirectToAction("Error", new { errorMessage = "The restaurant will be closed at this hour" }));
            }
            var result = basketUC.AddBasket(basketBTO);

            basketUC.ClearShoppingMeals();
            if (basketUC.shoppingMeals.Count == 0)
            {
                HttpContext.Session.Clear();
            }
            if (result == null)
            {
                return(RedirectToAction("Error", new { errorMessage = "We can't add this basket, please contact support" }));
            }
            string email = restoUC.FindRestoMailByRestoId(basketUC.restoId);

            if (!String.IsNullOrEmpty(email))
            {
                _emailSender.SendEmailAsync(email,
                                            "You have a new order",
                                            "See your orders by clicking here");
            }

            return(View(result));
        }
Ejemplo n.º 2
0
        public void Add_Meal_To_Basket_Ok()
        {
            //Arrange
            var     mock  = new Mock <IBasketRepository>();
            MealBTO meal1 = new MealBTO {
                Id = 1, Name = "M1"
            };
            MealBTO meal2 = new MealBTO {
                Id = 2, Name = "M2"
            };

            //Arrange
            BasketUC target = new BasketUC(mock.Object);

            //Act
            target.AddMealToBasket(meal1, 1);
            target.AddMealToBasket(meal2, 1);

            target.ClearShoppingMeals();

            //Assert
            Assert.AreEqual(target.shoppingMeals.Count, 0);
        }