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)); }
//Adds item to wishlist public void AddWishlistItem(WishlistInputModel model) { var connection = (from w in _db.UserBookWishlistConnections where w.UserID == model.UserID && w.BookID == model.BookID select w).FirstOrDefault(); if (connection == null) { var newWishlistItem = new UserBookWishlistConnectionEntityModel(model.UserID, model.BookID); _db.Add(newWishlistItem); _db.SaveChanges(); } }
public void AddWishlistItem(WishlistInputModel model) { _wishlistRepo.AddWishlistItem(model); }