public async Task <IActionResult> AddToWishlist(int?bookID, string controlla, string acta)
        {
            if (bookID == null)
            {
                return(View("NotFound"));
            }

            //Waits half a second so the add to wishlist animation can finish.
            System.Threading.Thread.Sleep(1000);

            //Gets the user and their id
            var user = await _userManager.GetUserAsync(User);

            var userID = user?.Id;

            //Creates the InputModel for the Wishlist.
            var newWishlistItem = new WishlistInputModel((int)bookID, userID);

            //Adds the wishlist connection from user to book.
            _wishlistService.AddWishlistItem(newWishlistItem);
            //Redirects the user to the Catalogue.
            if (acta == "Details")
            {
                return(RedirectToAction(acta, controlla, new { id = bookID }));
            }
            return(RedirectToAction(acta, controlla));
        }
예제 #2
0
        public async Task <ActionResult <WishlistItemViewModel> > AddWishlistItem([FromRoute] int productId, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            bool productExists = await _productService.ProductExists(productId, cancellationToken);

            if (!productExists)
            {
                return(NotFound());
            }

            WishlistItemViewModel viewModel = await _wishlistService.AddWishlistItem(productId, cancellationToken);

            return(Ok(viewModel));
        }