public async Task <WatchListPostDeleteDTO> DeleteWatchlistItem(string id, WatchListPostDeleteDTO watchListDeleteDTO)
        {
            if (watchListDeleteDTO == null)
            {
                throw new ArgumentNullException(nameof(watchListDeleteDTO));
            }

            try
            {
                WatchList watchlist = await _context.WatchLists
                                      .FirstOrDefaultAsync(w => w.UserId == id && w.MovieId == watchListDeleteDTO.MovieId).ConfigureAwait(false);

                _context.WatchLists.Remove(watchlist);

                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (await UserExists(id).ConfigureAwait(false) == false)
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }
            return(new WatchListPostDeleteDTO()
            {
                UserId = id,
                MovieId = watchListDeleteDTO.MovieId
            });
        }
Beispiel #2
0
        public async Task <ActionResult <WatchListPostDeleteDTO> > DeleteWatchlistItem(string id, WatchListPostDeleteDTO watchListDeleteDTO)
        {
            var watchlistResult = await _userRepository.DeleteWatchlistItem(id, watchListDeleteDTO).ConfigureAwait(false);

            if (watchlistResult == null)
            {
                return(NotFound());
            }

            return(watchlistResult);
        }