Пример #1
0
        public List <Movie> AddMovies(List <Movie> newMovies, bool ignoreErrors = false)
        {
            var added       = DateTime.UtcNow;
            var moviesToAdd = new List <Movie>();

            foreach (var m in newMovies)
            {
                _logger.Info("Adding Movie {0} Path: [{1}]", m, m.Path);

                try
                {
                    var movie = AddSkyhookData(m);
                    movie       = SetPropertiesAndValidate(movie);
                    movie.Added = added;
                    moviesToAdd.Add(movie);
                }
                catch (ValidationException ex)
                {
                    if (!ignoreErrors)
                    {
                        throw;
                    }

                    _logger.Debug("TmdbId {0} was not added due to validation failures. {1}", m.TmdbId, ex.Message);
                }
            }

            return(_movieService.AddMovies(moviesToAdd));
        }
        public async Task <IActionResult> AddMovies([FromBody] MovieDTO movieInfo)
        {
            if (movieInfo == null)
            {
                return(StatusCode(400, new { message = Constants.MissingOrInvalidBody }));
            }

            if (!ModelState.IsValid)
            {
                return(StatusCode(400, new { message = Constants.MissingOrInvalidBody }));
            }

            try
            {
                int bookingResponse = await _movieService.AddMovies(movieInfo);

                return(Created("AddedMovie", new { id = bookingResponse, Name = movieInfo.Movie_Name, Language = movieInfo.MovieLanguage }));
            }
            catch (CustomException ex)
            {
                return(StatusCode(400, new { message = ex.Message }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new { message = ex.Message }));
            }
        }
Пример #3
0
        private Response SaveAll()
        {
            var resources = Request.Body.FromJson <List <MovieResource> >();

            var Movies = resources.Select(MovieResource => _movieSearch.MapMovieToTmdbMovie(MovieResource.ToModel())).Where(m => m != null).DistinctBy(m => m.TmdbId).ToList();

            return(_movieService.AddMovies(Movies).ToResource().AsResponse(HttpStatusCode.Accepted));
        }
 public async Task <IActionResult> AddMovie([FromBody] Movie movie)
 {
     return(Ok(await _movieService.AddMovies(movie)));
 }