Ejemplo n.º 1
0
        public async Task ValidateForMarkingAsUnwatched(ToggleWatchedDto markAsUnwatched)
        {
            Validate(markAsUnwatched);

            var watchlist = await _uow.Repository <Domain.Entities.Watchlist>().FindOneAsync(new WatchlistWithFilmsSpecification(markAsUnwatched.WatchlistId));

            if (watchlist == null)
            {
                throw new NotFoundException(nameof(Domain.Entities.Watchlist));
            }

            if (_currentUserService.UserId != watchlist.UserId)
            {
                throw new ForbiddenException();
            }

            var film = watchlist.Films.FirstOrDefault(x => x.FilmId == markAsUnwatched.FilmId);

            AddValidationErrorIfValueIsNull(film, "Film", $"Id {markAsUnwatched.FilmId} not found in watchlist!");

            if (film != null && !film.IsWatched)
            {
                AddValidationError("Film", $"Id {film.FilmId} is not marked as watched!");
            }

            ThrowValidationErrorsIfNotEmpty();
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> MarkAsUnwatched(ToggleWatchedDto markAsUnwatched)
        {
            await _watchlistValidatorService.ValidateForMarkingAsUnwatched(markAsUnwatched);

            await _watchlistService.MarkAsUnwatched(markAsUnwatched);

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task MarkAsUnwatched(ToggleWatchedDto markAsUnwatched)
        {
            var watchlist = await _uow.Repository <Domain.Entities.Watchlist>().FindOneAsync(new WatchlistWithFilmsSpecification(markAsUnwatched.WatchlistId));

            var filmToMarkAsUnwatched = watchlist.Films.FirstOrDefault(x => x.FilmId == markAsUnwatched.FilmId);

            filmToMarkAsUnwatched.IsWatched = false;

            await _uow.SaveAsync();
        }