Exemplo n.º 1
0
        public async Task <IActionResult> Create(WatchlistForCreationDto watchlistForCreation)
        {
            await _watchlistValidatorService.ValidateForCreation(watchlistForCreation);

            var watchlist = await _watchlistService.Create(watchlistForCreation);

            return(CreatedAtRoute("GetWatchlist", new { controller = "Watchlist", id = watchlist.Id }, watchlist));
        }
        public async Task ValidateForCreation(WatchlistForCreationDto watchlistForCreation)
        {
            Validate(watchlistForCreation);

            ValidateSequence(watchlistForCreation.Films.Select(x => x.Sequence).ToList());

            await ValidateFilmIds(watchlistForCreation.Films.Select(x => x.FilmId).ToList());

            ThrowValidationErrorsIfNotEmpty();
        }
Exemplo n.º 3
0
        public async Task <WatchlistForDetailedDto> Create(WatchlistForCreationDto watchlistForCreation)
        {
            var watchlist = _mapper.Map <Domain.Entities.Watchlist>(watchlistForCreation);

            watchlist.UserId = (int)_currentUserService.UserId;

            _uow.Repository <Domain.Entities.Watchlist>().Add(watchlist);

            await _uow.SaveAsync();

            var watchlistToReturn = _mapper.Map <WatchlistForDetailedDto>(watchlist);

            await _photoService.IncludeMainPhoto(watchlistToReturn.Films, (int)EntityTypes.Film);

            return(watchlistToReturn);
        }