예제 #1
0
        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" }));
        }