Exemple #1
0
        public async Task <ActionResult> Post([FromForm] MovieCreationDto movieCreationDto)
        {
            var movie = _mapper.Map <Movie>(movieCreationDto);

            if (movieCreationDto.Poster != null)
            {
                using (var ms = new MemoryStream())
                {
                    await movieCreationDto.Poster.CopyToAsync(ms);

                    var content   = ms.ToArray();
                    var extension = Path.GetExtension(movieCreationDto.Poster.FileName);

                    movie.Poster = await _fileStorage.SaveFile(content, extension, _container, movieCreationDto.Poster.ContentType);
                }
            }

            AssignActorsOrder(movie);
            _context.Movies.Add(movie);
            await _context.SaveChangesAsync();

            var movieDto = _mapper.Map <MovieDto>(movie);

            return(CreatedAtAction("Get", new { id = movie.Id }, movieDto));
        }
Exemple #2
0
        public async Task <ActionResult> Put(int id, [FromForm] MovieCreationDto movieCreationDto)
        {
            var movie = await _context.Movies
                        .Include(m => m.MoviesActors)
                        .Include(m => m.MoviesGenres)
                        .FirstOrDefaultAsync(a => a.Id == id);

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

            movie = _mapper.Map(movieCreationDto, movie);

            if (movieCreationDto.Poster != null)
            {
                using (var ms = new MemoryStream())
                {
                    await movieCreationDto.Poster.CopyToAsync(ms);

                    var content   = ms.ToArray();
                    var extension = Path.GetExtension(movieCreationDto.Poster.FileName);

                    movie.Poster = await _fileStorage.EditFile(content, extension, _container, movie.Poster, movieCreationDto.Poster.ContentType);
                }
            }

            AssignActorsOrder(movie);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemple #3
0
        public async Task <ActionResult> Put(int id, [FromForm] MovieCreationDto movieCreation)
        {
            var movie = await _context.Movies.FirstOrDefaultAsync(x => x.Id == id);

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

            movie = _mapper.Map(movieCreation, movie);

            if (movieCreation.Poster != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await movieCreation.Poster.CopyToAsync(memoryStream);

                    var content   = memoryStream.ToArray();
                    var extension = Path.GetExtension(movieCreation.Poster.FileName);
                    movie.Poster =
                        await _fileStorageService.SaveFile(content, extension, containerName,
                                                           movieCreation.Poster.ContentType);
                }
            }

            await _context.Database.ExecuteSqlInterpolatedAsync($"delete from MoviesActors where MovieId = {movie.Id}; delete from MoviesGenres where MovieId = {movie.Id}");

            AnnotateActorsOrder(movie);

            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemple #4
0
        public async Task <ActionResult> Post([FromForm] MovieCreationDto movieCreation)
        {
            var movie = _mapper.Map <Movie>(movieCreation);

            if (movieCreation.Poster != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await movieCreation.Poster.CopyToAsync(memoryStream);

                    var content   = memoryStream.ToArray();
                    var extension = Path.GetExtension(movieCreation.Poster.FileName);
                    movie.Poster =
                        await _fileStorageService.SaveFile(content, extension, containerName,
                                                           movieCreation.Poster.ContentType);
                }
            }

            AnnotateActorsOrder(movie);

            _context.Add(movie);

            await _context.SaveChangesAsync();

            var movieDto = _mapper.Map <MovieDto>(movie);

            return(new CreatedAtRouteResult("getMovie", new { Id = movie.Id }, movieDto));
        }
        private List <MoviesActors> MapMoviesActors(MovieCreationDto movieCreationDto, Movie movie)
        {
            var moviesActors = new List <MoviesActors>();

            foreach (var actor in movieCreationDto.Actors)
            {
                moviesActors.Add(new MoviesActors {
                    PersonId = actor.PersonId, Character = actor.Character
                });
            }

            return(moviesActors);
        }
        private List <MoviesGenres> MapMoviesGenres(MovieCreationDto movieCreationDto, Movie movie)
        {
            var moviesGenres = new List <MoviesGenres>();

            foreach (var id in movieCreationDto.GenresIds)
            {
                moviesGenres.Add(new MoviesGenres {
                    GenreId = id
                });
            }

            return(moviesGenres);
        }
        public IActionResult PostMovie([FromBody] MovieCreationDto movieCreationDto)
        {
            Movie movie = new Movie();

            movie.Name        = movieCreationDto.Name;
            movie.ReleaseYear = movieCreationDto.ReleaseYear;
            movie.Runtime     = movieCreationDto.Runtime;
            movie.Summary     = movieCreationDto.Summary;
            movie.ImageUrl    = movieCreationDto.ImageUrl;

            Movie createdMovie = movieDbRepository.AddMovie(movie);

            try
            {
                if (movieCreationDto.Genres != null)
                {
                    foreach (string id in movieCreationDto.Genres.Split(','))
                    {
                        MovieGenre movieGenre = new MovieGenre()
                        {
                            GenreId = int.Parse(id), MovieId = createdMovie.MovieId
                        };
                        movieDbRepository.AddGenreToMovie(movieGenre);
                    }
                }
            }
            catch (Exception)
            {
            }

            try
            {
                if (movieCreationDto.Actors != null)
                {
                    foreach (string id in movieCreationDto.Actors.Split(','))
                    {
                        MovieActor movieActor = new MovieActor()
                        {
                            ActorId = int.Parse(id), MovieId = createdMovie.MovieId
                        };
                        movieDbRepository.AddActorToMovie(movieActor);
                    }
                }
            }
            catch (Exception)
            {
            }


            return(Ok());
        }
        public IActionResult UpdateMovie(int id, [FromBody] MovieCreationDto movieCreationDto)
        {
            Movie movie = new Movie();

            movie.Name        = movieCreationDto.Name;
            movie.ReleaseYear = movieCreationDto.ReleaseYear;
            movie.Runtime     = movieCreationDto.Runtime;
            movie.Summary     = movieCreationDto.Summary;
            movie.ImageUrl    = movieCreationDto.ImageUrl;
            movie.MovieId     = id;

            movieDbRepository.UpdateMovie(movie);

            return(Ok());
        }
        public async Task <ActionResult <int> > Post([FromForm] MovieCreationDto movieCreationDto)
        {
            var movie = mapper.Map <Movie>(movieCreationDto);

            if (movieCreationDto.Poster != null)
            {
                movie.Poster = await fileStorageService.SaveFile(container, movieCreationDto.Poster);
            }

            AnnotateActorsOrder(movie);
            context.Add(movie);
            await context.SaveChangesAsync();

            return(movie.Id);
        }
Exemple #10
0
        private List <MoviesActors> MapMoviesActors(MovieCreationDto movieCreationDto, Movie movie)
        {
            var result = new List <MoviesActors>();

            if (movieCreationDto.Actors == null)
            {
                return(result);
            }

            foreach (var actor in movieCreationDto.Actors)
            {
                result.Add(new MoviesActors()
                {
                    ActorId = actor.ActorId, Character = actor.Character
                });
            }

            return(result);
        }
Exemple #11
0
        private List <MoviesGenres> MapMoviesGenres(MovieCreationDto movieCreationDto, Movie movie)
        {
            var result = new List <MoviesGenres>();

            if (movieCreationDto.GenresId == null)
            {
                return(result);
            }

            foreach (var id in movieCreationDto.GenresId)
            {
                result.Add(new MoviesGenres()
                {
                    GenreId = id
                });
            }

            return(result);
        }
Exemple #12
0
        private List <MovieTheaterMovie> MapMovieTheatersMovies(MovieCreationDto movieCreationDto, Movie movie)
        {
            var result = new List <MovieTheaterMovie>();

            if (movieCreationDto.MovieTheatersIds == null)
            {
                return(result);
            }

            foreach (var id in movieCreationDto.MovieTheatersIds)
            {
                result.Add(new MovieTheaterMovie()
                {
                    MovieTheaterId = id
                });
            }

            return(result);
        }
        public async Task <ActionResult> Put(int id, [FromForm] MovieCreationDto movieCreationDto)
        {
            var movie = await context.Movies
                        .Include(x => x.MoviesActors)
                        .Include(x => x.MoviesGenres)
                        .Include(x => x.MovieTheatersMovies)
                        .FirstOrDefaultAsync(x => x.Id == id);

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

            movie = mapper.Map(movieCreationDto, movie);
            if (movieCreationDto.Poster != null)
            {
                movie.Poster = await fileStorageService.EditFile(container, movieCreationDto.Poster, movie.Poster);
            }

            AnnotateActorsOrder(movie);
            await context.SaveChangesAsync();

            return(NoContent());
        }