public ActionResult RemoveFromWishList(int id) { // Remove the item from the cart var wishListId = _unitOfWork.WishLists.GetWishListId(HttpContext); // Get the name of the product to display confirmation var productName = _unitOfWork.Products.Get(id).Name; // Remove from cart _unitOfWork.WishLists.RemoveFromWishList(id, wishListId); _unitOfWork.Complete(); // Display the confirmation message var results = new WishListRemoveViewModel() { Message = Server.HtmlEncode(productName) + " has been removed from your wish list.", Class = "addToWishList", Color = "text-danger", DeleteId = id }; return(Json(results)); }
public async Task <IActionResult> RemoveFromCart(string id, CancellationToken requestAborted) { // Retrieve the current user's shopping cart var cart = UserLogin(); // Get the name of the car to display confirmation var cartItem = await DbContext.WishListItems .Where(item => item.WishListItemId == id) .Include(c => c.Car) .SingleOrDefaultAsync(); string message; int itemCount; if (cartItem != null) { // Remove from cart itemCount = cart.RemoveFromWishList(id); await DbContext.SaveChangesAsync(requestAborted); string removed = (itemCount > 0) ? " 1 product van " : string.Empty; message = removed + cartItem.Car.brand + " " + cartItem.Car.model + " is uit uw wenslijst verwijderd."; } else { itemCount = 0; message = "Kon product niet vinden, er is niks uit u wenslijst verwijderd."; } // Display the confirmation message var results = new WishListRemoveViewModel { Message = message, ItemCount = itemCount, DeleteId = id }; _logger.LogInformation("Auto {id} is uit een wenslijst verwijderd.", id); return(Json(results)); }