Exemplo n.º 1
0
        public async Task <IActionResult> AddFilm(int filmListId, int tmdbId)
        {
            IActionResult result;
            var           list = await filmService.RetrieveFilmListById(filmListId);

            var film = await filmService.RetrieveFilmByTmdbId(tmdbId);

            if (list != null && film != null)
            {
                try
                {
                    var updatedList = await filmService.AddFilmToFilmList(list, film);

                    var listModel = filmListMapper.Map(updatedList);
                }
                catch (FilmListTemplatePublishedException)
                {
                    logger.LogInformation("Cannot add film to published film list template.");
                }
                result = RedirectToAction("View", new { filmListId = list.Id });
            }
            else
            {
                result = NotFound("Film list template with given ID not found.");
            }
            return(result);
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Models.FilmList> > AddFilm([FromForm] int filmListId, [FromForm] int tmdbId)
        {
            var list = await filmService.RetrieveFilmListById(filmListId);

            var film = await filmService.RetrieveFilmByTmdbId(tmdbId);

            if (list != null && film != null)
            {
                try
                {
                    var updatedList = await filmService.AddFilmToFilmList(list, film);

                    var listModel = filmListMapper.Map(updatedList);
                    return(listModel);
                }
                catch (FilmListTemplatePublishedException)
                {
                    logger.LogInformation("Cannot add film to published film list.");
                    var listModel = filmListMapper.Map(list);
                    return(listModel);
                }
                catch (FilmAlreadyInFilmListTemplateException)
                {
                    return(BadRequest($"Lists cannot have duplicate films. {film.Name} is already in the list."));
                }
            }
            else
            {
                return(NotFound());
            }
        }