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)); }
public BasketBTO UpdateBasket(BasketBTO basketBto) { BasketDTO basket; if (basketBto != null) { basket = basketRepository.Update(basketBto.BTOToBasketDomain().BasketDomainToDTO()); return(basket?.DTOToBasketDomain().BasketDomainToBTO() ?? null); } return(null); }
public BasketBTO AddBasket(BasketBTO basketBto) { BasketDTO meal = new BasketDTO(); if (basketBto != null) { var domain = basketBto.BTOToBasketDomain(); meal = basketRepository.Create(domain.BasketDomainToDTO()); return(meal.DTOToBasketDomain().BasketDomainToBTO()); } return(null); }
public IActionResult EditBasket(BasketBTO basketBTO) { if (!ModelState.IsValid) { return(View(basketBTO)); } var result = GetBasketUC().UpdateBasket(basketBTO); if (result == null) { return(RedirectToAction("Error", new { errorMessage = "We can't update this meal, please contact support" })); } return(View(result)); }
public static BasketDomain BTOToBasketDomain(this BasketBTO basketBto) { if (basketBto != null) { return new BasketDomain { Id = basketBto.Id, UserId = basketBto.UserId, User = basketBto.User.UserBTOToUserDomain(), ShoppingMeals = basketBto.ShoppingMeals? .Select(x => x.BTOToShoppingMealDomain()) .ToList() ?? null, ArrivalDate = basketBto.ArrivalDate } } ; else { return(null); } }
public PartialViewResult Summary(BasketBTO basket) { return(PartialView(basket)); }