public async Task <IActionResult> Delete(long id) { if (!await mealService.ValidateAccessAsync(id, User)) { return(RedirectToAction(nameof(HomeController.Index), "Home")); } var meal = await mealService.GetMealByIdAsync(id); await mealService.DeleteMealAsync(id); return(RedirectToAction(nameof(RestaurantController.Edit), "Restaurant", new { id = meal.Restaurant.RestaurantId })); }
public async Task <Order> AddMealToOrderAsync(long mealId, string userName) { var meal = await mealService.GetMealByIdAsync(mealId); var shoppingCart = await GetShoppingCartByUserAndRestaurantAsync(userName, meal.Restaurant.RestaurantId); if (shoppingCart != null) { if (meal != null) { var cartItem = await applicationDbContext.CartItems .FirstOrDefaultAsync(c => c.Meal == meal && c.Order == shoppingCart); if (cartItem == null) { var newCartItem = new CartItem() { Quantity = 1, Meal = meal, Order = shoppingCart }; await applicationDbContext.CartItems.AddAsync(newCartItem); } else { cartItem.Quantity++; } await applicationDbContext.SaveChangesAsync(); } } return(shoppingCart); }
public async Task <IActionResult> Add(long id) { var shoppingCart = await orderService.AddMealToOrderAsync(id, User.Identity.Name); var meal = await mealService.GetMealByIdAsync(id); return(RedirectToAction(nameof(RestaurantController.Index), "Restaurant", new { id = meal.Restaurant.RestaurantId })); }
public async Task <IActionResult> GetMeal(Guid mealId) { if (mealId == Guid.Empty) { return(NotFound()); } var userId = new Guid(User.Identity.Name); var meal = await _mealService.GetMealByIdAsync(userId, mealId); if (meal == null) { return(NotFound()); } return(Ok(meal)); }
public async Task <ActionResult> DetailsMeal(int?id) { var model = await _mealService.GetMealByIdAsync(id.GetValueOrDefault()); return(View(model)); }