public IActionResult WatchList([FromBody] WatchlistPostModel watchlistPostModel) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var watchList = _watchListRepository.GetWatchListForUserForProduct(userId, watchlistPostModel.ProductId); if (watchList == null) { WatchList newWatchlist = new WatchList() { ProductId = watchlistPostModel.ProductId, UserID = userId, }; _watchListRepository.AddWatchlist(newWatchlist); return(Json(new { success = "true" })); } else if (watchList.UserID.Equals(userId)) { _watchListRepository.RemoveWatchlist(watchList); return(Json(new { success = "true" })); } return(Json(new { success = "false" })); }
public IActionResult Detail(int id) { var product = _productRepository.GetProductById(id); if (product == null) { return(NotFound()); } ProductViewModel productView = new ProductViewModel(); productView.Product = product; productView.Categories = _categoryRepository.AllCategory; if (User.Identity.IsAuthenticated) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var offer = _offerRepository.GetOfferForProductByUser(product.ProductId, userId); var watchlist = _watchListRepository.GetWatchListForUserForProduct(userId, product.ProductId); if (offer != null) { if (offer.isPending) { productView.HasOffer = true; } } else { productView.HasOffer = false; } if (watchlist != null) { productView.HasWatchlist = true; } else { productView.HasWatchlist = false; } } return(View(productView)); }