public void AddMovie_MovieIsAdded()
        {
            var movie = new Movie {
                Id = 5, Name = "Movie Test", Comments = "comments1", PosterPath = "pp.jpg", ReleaseDate = "releaseDate1", VoteAverage = 5.00, VoteCount = 100
            };

            _repo.AddMovie(movie);
            var savedMovie = _repo.GetMovie(5);

            Assert.Equal("Movie Test", savedMovie.Name);
        }
        public void AddMovie_MovieAdded()
        {
            var movie = new Movie {
                Id = 127, Title = "Iron Man7", PosterPath = "IronMan7.jpg"
            };

            _movieRepository.AddMovie(movie);
            var savedMovie = _movieRepository.GetMovie(127);

            Assert.Equal("Iron Man7", savedMovie.Title);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateMovieAsync(
            [FromBody, SwaggerParameter(Description = "Movie to create", Required = true)] MovieToCreateDto movieToCreate,
            [FromHeader(Name = "Accept"), SwaggerParameter(Description = "media type to request betwen json or json+hateoas")] string mediaType)
        {
            var movieToAdd = Mapper.Map <Movie>(movieToCreate);

            movieToAdd.Id = Guid.NewGuid();

            _movieRepository.AddMovie(movieToAdd);

            if (!await _movieRepository.SaveChangesAsync())
            {
                _logger.LogError("Saving changes to database while creating a movie failed");
            }

            // if any genre is added to movie, create many-to-many relationship for each genre
            if (movieToCreate.GenreIds != null && movieToCreate.GenreIds.Count > 0)
            {
                for (int i = 0; i < movieToCreate.GenreIds.Count; i++)
                {
                    // create moviegenre object with genre id and movie id from movieToCreate object
                    MovieGenre movieGenreToAdd = new MovieGenre {
                        MovieId = movieToAdd.Id, GenreId = movieToCreate.GenreIds[i]
                    };
                    movieGenreToAdd.Id = Guid.NewGuid();
                    _movieGenreRepository.AddMovieGenre(movieGenreToAdd);
                }
                // save changes to database after all many-to-many relationships has been created
                if (!await _movieGenreRepository.SaveChangesAsync())
                {
                    _logger.LogError("Saving changes to database while creating a moviegenre failed");
                }
            }

            var foundMovie = await _movieRepository.GetMovieAsync(movieToAdd.Id);

            var movieDto = Mapper.Map <MovieDto>(foundMovie);

            if (mediaType == "application/vnd.biob.json+hateoas")
            {
                var links = CreateLinksForMovies(movieDto.Id, null);

                var linkedMovie = movieDto.ShapeData(null) as IDictionary <string, object>;

                linkedMovie.Add("links", links);

                return(CreatedAtRoute("GetMovie", new { movieId = movieDto.Id }, linkedMovie));
            }
            else
            {
                return(CreatedAtRoute("GetMovie", new { movieId = movieDto.Id }, movieDto));
            }
        }
        public void AddMovie_ShouldReturnMovie_forValidMovieId()
        {
            //arrange
            Movie newMovie = new Movie {
                Id = 10004, Name = "Spiderman", Comments = string.Empty, PosterPath = "spiderman.jpg", ReleaseDate = "13-10-2003", VoteCount = 82345, VoteAverage = 7.9, UserId = "user1"
            };
            //act
            var actual = _repository.AddMovie(newMovie);

            //assert
            Assert.NotNull(actual);
            Assert.Same(newMovie, actual);
        }
Exemplo n.º 5
0
        public async Task <ExtendedMovieDTO> AddMovie(ExtendedMovieDTO movie)
        {
            Movie newMovie = _mapper.Map <Movie>(movie);
            await _movieRepository.AddMovie(newMovie);

            return(movie);
        }
Exemplo n.º 6
0
        public async Task <BaseResponse <bool> > Handle(AddMovieRequest request, CancellationToken cancellationToken)
        {
            BaseResponse <bool> response = new BaseResponse <bool>();

            try
            {
                var movie = new Movie(request.Id, request.Title, request.ReleaseDate);
                movie.SetBackDropPath(request.BackdropPath);
                movie.SetIsAdult(request.IsAdult);
                movie.SetOrginalLanguage(request.OriginalLanguage);
                movie.SetOriginalTitle(request.OriginalTitle);
                movie.SetPosterPath(request.PosterPath);
                movie.SetPopularity(request.Popularity);
                movie.SetOverview(request.Overview);
                await _movieRepository.AddMovie(movie);

                response.Data = true;
            }
            catch (Exception ex)

            {
                response.Errors.Add(ex.Message);
                _logger.LogError("--- Adding Movie Error", "Movie Id:" + request.Id, "Message: " + ex.Message);
            }
            return(response);
        }
Exemplo n.º 7
0
        public async Task <IActionResult> AddMovie([FromBody] MovieToBeRegisteredDto movieToBeRegisteredDto)
        {
            var contributor = await _movieRepo.GetContributor(movieToBeRegisteredDto.ContributorName);

            var movieToCreate = _mapper.Map <Movie>(movieToBeRegisteredDto);

            try
            {
                if (contributor == null)
                {
                    var contributorToBeAdded = new Contributor
                    {
                        Name        = movieToBeRegisteredDto.ContributorName,
                        Description = "I`m not sure what to put here",
                        Title       = " some title"
                    };

                    var addContributor = _movieRepo.AddContributor(contributorToBeAdded);
                    movieToCreate.Contributors.Add(addContributor);
                }


                var createdMovie = await _movieRepo.AddMovie(movieToCreate);

                return(CreatedAtRoute("GetMovie", new { controller = "Movie", id = movieToCreate.ID }, movieToCreate));
            }
            catch (Exception)
            {
                throw new Exception("Something terrible happened");
            }
        }
Exemplo n.º 8
0
        public void AddMovie(MovieDTO movieDTO)
        {
            int movieId = _movieRepository.AddMovie(movieDTO);

            if (movieDTO.Actors == null || !movieDTO.Actors.Any())
            {
                return;
            }
            List <int> actorsIds = new List <int>();

            foreach (string actor in movieDTO.Actors)
            {
                ActorDTO actorFromDb = _actorRepository.GetActorByName(actor);
                if (actorFromDb == null)
                {
                    actorsIds.Add(_actorRepository.AddActor(new ActorDTO {
                        ActorName = actor
                    }));
                }
                else
                {
                    actorsIds.Add(actorFromDb.ActorId);
                }
            }
            foreach (int actorId in actorsIds)
            {
                _actorRepository.AddActorByMovieId(actorId, movieId);
            }
        }
Exemplo n.º 9
0
        private void btSave_Click(object sender, EventArgs e)
        {
            var movie = new Movie();

            movie.Title = textBox1.Text;
            movie.Staff = chklbStaff.CheckedItems.Cast <MovieStar>();
            _movieRepository.AddMovie(movie);
        }
Exemplo n.º 10
0
        public async Task CreateMovie(CreateMovie command)
        {
            var director = _directorRepository.GetAsync(command.DirectorId);
            var movie    = await _movieRepository.CreateAsync(command.Title, command.DurationMinutes);

            movie.SetDirector(await director);

            await _movieRepository.AddMovie(movie);
        }
Exemplo n.º 11
0
 public IActionResult EnterMovie(Movie movie)
 {
     Debug.WriteLine(movie.Category);
     if (ModelState.IsValid)
     {
         _repository.AddMovie(movie);
     }
     return(View());
 }
 public IActionResult Create(Movie movie)
 {
     if (ModelState.IsValid)
     {
         Movie newMovie = _movieRepository.AddMovie(movie);
         return(RedirectToAction("index", new { id = newMovie.Id }));
     }
     return(View());
 }
Exemplo n.º 13
0
        public IHttpActionResult Post([FromBody] MovieViewModel movie)
        {
            var id = new
            {
                id = repository.AddMovie(movie)
            };

            return(Created("/api/movie/" + id, id));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price,Rating")] MovieDTO movie)
        {
            if (ModelState.IsValid)
            {
                _repo.AddMovie(movie);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
Exemplo n.º 15
0
 public IActionResult Create([Bind("ID,Name,ReleaseYear,Rating")] Movie movie)
 {
     if (ModelState.IsValid)
     {
         _context.AddMovie(movie);
         //await _context.SaveChangesAsync();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(movie));
 }
Exemplo n.º 16
0
 public ActionResult Create([Bind(Include = "nazwa,rodzaj,rok_produkcji,director_id")] Movie movie)
 {
     if (ModelState.IsValid)
     {
         _movieRepository.AddMovie(movie);
         _movieRepository.Save();
         return(RedirectToAction("Index"));
     }
     return(View(movie));
 }
Exemplo n.º 17
0
        public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price,Rating")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                await _movieRepository.AddMovie(movie);

                return(RedirectToAction("Index"));
            }

            return(View(movie));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> AddMovie(CreateMovieModel model)
        {
            var result = await _movieRepository.AddMovie(model);

            if (result >= 1)
            {
                return(Ok(new { Message = "Movie added succesfully. cambio 4" }));
            }

            return(StatusCode(500, new { Message = "Some error happened." }));
        }
Exemplo n.º 19
0
        public async Task <ActionResult> Add(MovieDetailViewModel vm)
        {
            await _movieRepository.AddMovie(new Movie
            {
                Title    = vm.Title,
                Director = vm.Director,
                Genre    = await _genreRepository.GetGenreById(vm.GenreId)
            });

            return(RedirectToAction("Index"));
        }
Exemplo n.º 20
0
        public IActionResult CreateMovie([FromBody] Movie movie)
        {
            if (movie == null)
            {
                return(BadRequest());
            }

            var createdMovie = _movieRepository.AddMovie(movie);

            return(Created("Movie", createdMovie));
        }
Exemplo n.º 21
0
 public void Post([FromBody] Movie value)
 {
     _movieRepository.AddMovie(new Movie()
     {
         Title       = value.Title,
         ReleaseDate = value.ReleaseDate,
         Genre       = value.Genre,
         Price       = value.Price,
         Rating      = value.Rating
     });
 }
Exemplo n.º 22
0
        public ActionResult <Movie> Post([FromBody] Movie newMovie)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _movieRepository.AddMovie(newMovie);

            // The id will be updated because the object is passed by reference.
            return(CreatedAtAction(nameof(Post), newMovie));
        }
Exemplo n.º 23
0
        public ActionResult Create([Bind(Include = "nazwa,rodzaj,rok_produkcji,director_id")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _movieRepository.AddMovie(movie);
                _movieRepository.Save();
                return(RedirectToAction("Index"));
            }

            ViewBag.director_id = new SelectList(db.Director, "Id", "imie", movie.director_id);
            return(View(movie));
        }
Exemplo n.º 24
0
        public Mutations(IMovieRepository movieRepository)
        {
            this.Name = nameof(Mutations);

            this.Field <MovieType, Movie>("createMovie")
            .Argument <InputMovieType>("movie", "movie to create")
            .Resolve(x =>
            {
                var movie = x.GetArgument <Movie>("movie");
                return(movieRepository.AddMovie(movie));
            });
        }
Exemplo n.º 25
0
        public ActionResult Create([Bind(Include = "ID,Title,ReleaseDate,Genre,Price,Rating,BinderId")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                if (db.AddMovie(movie))
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(View(movie));
        }
Exemplo n.º 26
0
        public async Task <ActionResult> AddMovie([FromBody] MovieViewModel movie)
        {
            try
            {
                if (movie.Thumbnail.ToLower().Contains("http"))
                {
                    _log.LogInformation("AddMovie() endpoint called");
                    var res = _helper.SaveImage(movie.Thumbnail, "Movie");
                    movie.Thumbnail = res;
                    return(Ok(await _movieRepository.AddMovie(movie)));
                }


                return(Ok(await _movieRepository.AddMovie(movie)));
            }
            catch (Exception e)
            {
                _log.LogError("couldn't Add Movie", e, $"Exception({movie})", movie);
                return(StatusCode(500));
            }
        }
        public Movie AddMovie(Movie movie)
        {
            Movie m = this.GetByTitle(movie.Title);

            if (this.GetByTitle(movie.Title) == null && movie.Date.Year > 1980)
            {
                return(_movieRepository.AddMovie(movie));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 28
0
        public async Task <MoviesDTO> AddMovie(MoviesDTO Movie)
        {
            try
            {
                Movies newMovie = _mapper.Map <Movies>(Movie);
                await _movieRepository.AddMovie(newMovie);

                return(Movie);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 29
0
 public async Task <IActionResult> Post([FromBody] MovieViewModel theMovie)
 {
     if (ModelState.IsValid)
     {
         // save to the database automap
         var newMovie = Mapper.Map <Movie>(theMovie);
         _repository.AddMovie(newMovie);
         if (await _repository.SaveChangesAsync())
         {
             return(Created($"api/movies/{theMovie.Title}", Mapper.Map <MovieViewModel>(newMovie)));
         }
     }
     return(BadRequest("Failed to save the Movie"));
 }
Exemplo n.º 30
0
        public async Task <bool> AddMovie(ValueObjects.Movie movie)
        {
            // ideally Automapper
            var domain = new Movie
            {
                Id          = movie.Id,
                MovieId     = movie.MovieId,
                Title       = movie.Title,
                Language    = movie.Language,
                Duration    = TimeSpan.Parse(movie.Duration),
                ReleaseYear = movie.ReleaseYear
            };

            return(await _movieRepository.AddMovie(domain));
        }