Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("MovieRoleID,ActorID,MovieID,Character")] MovieRole movieRole)
        {
            if (id != movieRole.MovieRoleID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movieRole);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieRoleExists(movieRole.MovieRoleID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ActorID"] = new SelectList(_context.Actor, "ActorID", "Name", movieRole.ActorID);
            ViewData["MovieID"] = new SelectList(_context.Movie, "ID", "Genre", movieRole.MovieID);
            return(View(movieRole));
        }
Пример #2
0
        public void AddPersonToMovie(int movieId, int personId, Role role)
        {
            var personToAdd = this.personRepository.GetById(personId);

            Guard.WhenArgument(personToAdd, "Person").IsNull().Throw();

            var movie = this.movieRepository.GetById(movieId);

            Guard.WhenArgument(movie, "Movie").IsNull().Throw();

            if (movie.People.Contains(personToAdd))
            {
                return;
            }

            movie.People.Add(personToAdd);
            this.movieRepository.Update(movie);

            var movieRole = new MovieRole()
            {
                PersonId  = personId,
                Role      = role,
                MovieId   = movieId,
                CreatedOn = DateTime.UtcNow
            };

            this.movieRoleRepository.Add(movieRole);
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Actor,Character,Movie")] MovieRole movieRole)
        {
            if (id != movieRole.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movieRole);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieRoleExists(movieRole.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(movieRole));
        }
Пример #4
0
        public void TestPersonsGetPersonMovieCredits()
        {
            MovieCredits item = Config.Client.GetPersonMovieCreditsAsync(IdHelper.BruceWillis).Result;

            Assert.NotNull(item);
            Assert.NotNull(item.Cast);
            Assert.NotNull(item.Crew);

            Assert.Equal(IdHelper.BruceWillis, item.Id);

            MovieRole cast = item.Cast.SingleOrDefault(s => s.CreditId == "52fe4329c3a36847f803f193");

            Assert.NotNull(cast);
            Assert.Equal(false, cast.Adult);
            Assert.Equal("Lieutenant Muldoon", cast.Character);
            Assert.Equal("52fe4329c3a36847f803f193", cast.CreditId);
            Assert.Equal(1992, cast.Id);
            Assert.Equal("Planet Terror", cast.OriginalTitle);
            Assert.True(TestImagesHelpers.TestImagePath(cast.PosterPath), "cast.PosterPath was not a valid image path, was: " + cast.PosterPath);
            Assert.Equal(new DateTime(2007, 4, 6), cast.ReleaseDate);
            Assert.Equal("Planet Terror", cast.Title);

            MovieJob job = item.Crew.SingleOrDefault(s => s.CreditId == "52fe432ec3a36847f8040603");

            Assert.NotNull(job);
            Assert.Equal(false, job.Adult);
            Assert.Equal("52fe432ec3a36847f8040603", job.CreditId);
            Assert.Equal("Production", job.Department);
            Assert.Equal(2026, job.Id);
            Assert.Equal("Producer", job.Job);
            Assert.Equal(new DateTime(2005, 3, 9), job.ReleaseDate);
            Assert.True(TestImagesHelpers.TestImagePath(job.PosterPath), "job.PosterPath was not a valid image path, was: " + job.PosterPath);
            Assert.Equal("Hostage", job.Title);
            Assert.Equal("Hostage", job.OriginalTitle);
        }
Пример #5
0
        public void TestPersonsGetPersonMovieCredits()
        {
            MovieCredits item = _config.Client.GetPersonMovieCredits(BruceWillis);

            Assert.IsNotNull(item);
            Assert.IsNotNull(item.Cast);
            Assert.IsNotNull(item.Crew);

            Assert.AreEqual(BruceWillis, item.Id);

            MovieRole cast = item.Cast.SingleOrDefault(s => s.CreditId == "52fe4329c3a36847f803f193");

            Assert.IsNotNull(cast);
            Assert.AreEqual(false, cast.Adult);
            Assert.AreEqual("Lieutenant Muldoon", cast.Character);
            Assert.AreEqual("52fe4329c3a36847f803f193", cast.CreditId);
            Assert.AreEqual(1992, cast.Id);
            Assert.AreEqual("Planet Terror", cast.OriginalTitle);
            Assert.AreEqual("/7Yjzttt0VfPphSsUg8vFUO9WaEt.jpg", cast.PosterPath);
            Assert.AreEqual(new DateTime(2007, 4, 6), cast.ReleaseDate);
            Assert.AreEqual("Planet Terror", cast.Title);

            MovieJob job = item.Crew.SingleOrDefault(s => s.CreditId == "52fe42fec3a36847f8032887");

            Assert.IsNotNull(job);
            Assert.AreEqual(false, job.Adult);
            Assert.AreEqual("52fe42fec3a36847f8032887", job.CreditId);
            Assert.AreEqual("Production", job.Department);
            Assert.AreEqual(1571, job.Id);
            Assert.AreEqual("Producer", job.Job);
            Assert.AreEqual(new DateTime(2007, 6, 21), job.ReleaseDate);
            Assert.AreEqual("/8czarUCdvqPnulkLX8mdXyrLk2D.jpg", job.PosterPath);
            Assert.AreEqual("Live Free or Die Hard", job.Title);
            Assert.AreEqual("Live Free or Die Hard", job.OriginalTitle);
        }
Пример #6
0
        public static void MapFromView(Actor sourceActor, Actor destinationActor, ISession session)
        {
            destinationActor.Name        = sourceActor.Name;
            destinationActor.BirthDate   = sourceActor.BirthDate;
            destinationActor.Nationality = sourceActor.Nationality;

            var movieIds   = sourceActor.MovieRoles.Select(r => r.Movie.Id).ToSet();
            var movies     = session.Query <Movie>().Where(m => movieIds.Contains(m.Id));
            var moviesById = movies.ToDictionary(m => m.Id, m => m);

            foreach (var sourceRole in sourceActor.MovieRoles)
            {
                MovieRole destinationRole;
                if (sourceRole.Id == 0)
                {
                    destinationRole = new MovieRole {
                    };
                    destinationActor.MovieRoles.Add(destinationRole);
                }
                else
                {
                    destinationRole = destinationActor.MovieRoles.Single(r => r.Id == sourceRole.Id);
                }
                destinationRole.Title = sourceRole.Title;
                destinationRole.Actor = destinationActor;
                destinationRole.Movie = moviesById[sourceRole.Movie.Id];
            }

            destinationActor.MovieRoles.RemoveWhere(destinationRole => destinationRole.IsPersisted && !sourceActor.MovieRoles.Any(sourceRole => object.Equals(sourceRole, destinationRole)));
        }
Пример #7
0
        public static void MapFromView(Movie sourceMovie, Movie destinationMovie, ISession session)
        {
            destinationMovie.Title           = sourceMovie.Title;
            destinationMovie.CountryOfOrigin = sourceMovie.CountryOfOrigin;
            destinationMovie.ReleaseDate     = sourceMovie.ReleaseDate;

            var actorIds   = sourceMovie.MovieRoles.Select(r => r.Actor.Id).ToSet();
            var actors     = session.Query <Actor>().Where(a => actorIds.Contains(a.Id));
            var actorsById = actors.ToDictionary(a => a.Id, a => a);

            foreach (var sourceRole in sourceMovie.MovieRoles)
            {
                MovieRole destinationRole;
                if (sourceRole.Id == 0)
                {
                    destinationRole = new MovieRole {
                    };
                    destinationMovie.MovieRoles.Add(destinationRole);
                }
                else
                {
                    destinationRole = destinationMovie.MovieRoles.Single(r => r.Id == sourceRole.Id);
                }
                destinationRole.Title = sourceRole.Title;
                destinationRole.Movie = destinationMovie;
                destinationRole.Actor = actorsById[sourceRole.Actor.Id];
            }

            destinationMovie.MovieRoles.RemoveWhere(destinationRole => destinationRole.IsPersisted && !sourceMovie.MovieRoles.Any(sourceRole => object.Equals(sourceRole, destinationRole)));
        }
Пример #8
0
 public void Delete(MovieRole delMovieRole)
 {
     if (delMovieRole != null)
     {
         db.MovieRole.Remove(delMovieRole);
         db.SaveChanges();
     }
 }
Пример #9
0
        public async Task <IActionResult> CreateMovieRole(MovieRole movieRole)
        {
            var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (await appRepository.GetMovieRoleByParams(movieRole.MovieId, movieRole.ArtistId, movieRole.RoleTypeId) != null ||
                await appRepository.GetMovieRoleByParams(movieRole.MovieId, movieRole.ArtistId, movieRole.RoleTypeId, userId) != null)
            {
                return(BadRequest("The movie role already exists"));
            }
            var artist = await appRepository.GetArtist(movieRole.ArtistId);

            if (artist == null)
            {
                artist = await appRepository.GetArtist(movieRole.ArtistId, userId);
            }
            if (artist == null)
            {
                return(BadRequest("The artist does not exist"));
            }
            movieRole.Artist           = artist;
            movieRole.IsArtistApproved = artist.IsApproved;
            var movie = await appRepository.GetMovie(movieRole.MovieId);

            if (movie == null)
            {
                movie = await appRepository.GetMovie(movieRole.MovieId, userId);
            }
            if (movie == null)
            {
                return(BadRequest("The movie does not exist"));
            }
            movieRole.Movie           = movie;
            movieRole.IsMovieApproved = movie.IsApproved;
            var roleType = await appRepository.GetRoleType(movieRole.RoleTypeId);

            if (roleType == null)
            {
                return(BadRequest("The role type does not exist"));
            }
            appRepository.Add(movieRole);
            if (await appRepository.SaveAll())
            {
                var activity = new MovieRoleActivityLog();
                activity.RoleDescription = movieRole.RoleDescription;
                activity.AddedByUserId   = userId;
                activity.MovieRoleId     = movieRole.Id;
                appRepository.Add(activity);
                if (await appRepository.SaveAll())
                {
                    return(CreatedAtRoute("GetMovieRole", new { id = movieRole.Id }, movieRole));
                }
                return(BadRequest("Unable to Add Movie Role"));
            }
            return(BadRequest("Unable to Add Movie Role"));
        }
        public async Task GetArtistAndDetailsByIdAsyncShouldReturnCorrectModelIfDataIsValid()
        {
            var artist1 = new Artist
            {
                FullName  = "name1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            var movie1 = new Movie
            {
                Name        = "movie1",
                ReleaseDate = DateTime.Parse("24 July 2019"),
                Description = "something",
                Length      = 150,
                Genre       = new Genre {
                    Name = "Crime"
                },
                CoverImageLink = "image",
                TrailerLink    = "trailer",
                Director       = artist1,
            };
            var movieRole1 = new MovieRole
            {
                Movie           = movie1,
                Artist          = artist1,
                CharacterPlayed = "character",
            };
            await dbContext.Artists.AddAsync(artist1);

            await dbContext.Movies.AddAsync(movie1);

            await dbContext.MovieRoles.AddAsync(movieRole1);

            await dbContext.SaveChangesAsync();

            var id = dbContext.Artists.First().Id;

            var artistService = new ArtistService(dbContext, mapper);

            var actualResult = await artistService.GetArtistAndDetailsByIdAsync(id);

            Assert.True(actualResult.FullName == "name1");
            Assert.True(actualResult.Biography == "biography1");
            Assert.True(actualResult.BirthDate == DateTime.Parse("25 July 2019"));
            Assert.True(actualResult.PhotoLink == "photo1");
            Assert.True(actualResult.SeasonRoles.Count() == 0);
            Assert.True(actualResult.TVShowsCreated.Count() == 0);
            Assert.True(actualResult.MovieRoles.Count() == 1);
            Assert.True(actualResult.MoviesDirected.Count() == 1);
            Assert.True(actualResult.MovieRoles.First().Key == "movie1" && actualResult.MovieRoles.First().Value == "character");
            Assert.True(actualResult.MoviesDirected.First() == "movie1");
        }
Пример #11
0
        public async Task <IActionResult> Create([Bind("MovieRoleID,ActorID,MovieID,Character")] MovieRole movieRole)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movieRole);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ActorID"] = new SelectList(_context.Actor, "ActorID", "Name", movieRole.ActorID);
            ViewData["MovieID"] = new SelectList(_context.Movie, "ID", "Genre", movieRole.MovieID);
            return(View(movieRole));
        }
Пример #12
0
        public async Task <IActionResult> Create(string newRole, string newActor, string newMovie)
        {
            //creates a new MovieRole and adds to DB
            var movieRole = new MovieRole
            {
                Actor     = _context.Actor.Where(a => a.Name == newActor).First(),
                Character = newRole,
                Movie     = _context.Movie.Where(m => m.Title == newMovie).First()
            };

            _context.Add(movieRole);
            await _context.SaveChangesAsync();

            return(Json(new { Result = "Success", Message = "New Role Added" }));
        }
Пример #13
0
        public async Task TestGetPersonMovieCreditsAsync()
        {
            MovieCredits item = await TMDbClient.GetPersonMovieCreditsAsync(IdHelper.BruceWillis);

            Assert.NotNull(item);
            Assert.NotEmpty(item.Cast);
            Assert.NotEmpty(item.Crew);

            MovieRole cast = item.Cast.Single(s => s.CreditId == "52fe4329c3a36847f803f193");
            MovieJob  crew = item.Crew.Single(s => s.CreditId == "52fe432ec3a36847f8040603");

            await Verify(new
            {
                cast,
                crew
            });
        }
Пример #14
0
        public async Task AddNewMovieRole(MovieRole role)
        {
            var movie = await _moviesContext.Movies.FindAsync(role.MovieId);

            if (movie == null)
            {
                throw new MovieApiException("Invalid movie Id");
            }
            var actor = await _moviesContext.Actors.FindAsync(role.ActorId);

            if (actor == null)
            {
                throw new MovieApiException("Invalid actor Id");
            }

            _moviesContext.MovieRoles.Add(role);
            await _moviesContext.SaveChangesAsync();
        }
Пример #15
0
        public async Task <bool> UpdateMovieRole(MovieRole role)
        {
            var foundRole = await GetMovieRoleById(role.Id);

            var movie = await _moviesContext.Movies.FindAsync(role.MovieId);

            var actor = await _moviesContext.Actors.FindAsync(role.ActorId);

            if (foundRole == null || movie == null || actor == null)
            {
                return(false);
            }

            foundRole.ActorId = role.ActorId;
            foundRole.MovieId = role.MovieId;

            await _moviesContext.SaveChangesAsync();

            return(true);
        }
Пример #16
0
        public async Task <JsonResult> SaveRow([Bind("MovieRoleID,ActorID,MovieID,Character")] MovieRole movieRole)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movieRole);
                await _context.SaveChangesAsync();
            }

            var query = await(from actor in _context.Actor
                              where actor.ActorID == movieRole.ActorID
                              select actor).FirstOrDefaultAsync();

            IDictionary <string, string> jsonObject = new Dictionary <string, string>()
            {
                { "Name", query.Name },
                { "Character", movieRole.Character },
                { "MovieRoleID", movieRole.MovieRoleID.ToString() }
            };

            return(Json(jsonObject));
        }
Пример #17
0
 public void Update(MovieRole updMovieRole)
 {
     db.MovieRole.Update(updMovieRole);
     db.SaveChanges();
 }
        public ActionResult ShowTrailler(AddProjectionVM model, string ButtonType)
        {
            //if (!ModelState.IsValid)
            //    return RedirectToAction("AddProjection", model);
            if (ButtonType != "next")
            {
                model.Traillers = Algorithm.SuggestTrailerLinks(model.Projection.Movie.MovieName, 3);
            }

            if (ButtonType == "save")
            {
                Movie m = model.Projection.Movie;
                m.IsDeleted = false;
                m.GenreID   = model.GenreID;
                m.Genre     = principal.Genres.Where(x => x.GenreID == model.GenreID).First();
                m.Trailler  = model.Traillers[0];
                principal.Movies.Add(m);
                principal.SaveChanges();

                foreach (int i in model.ActorsIDs)
                {
                    MovieRole mr = new MovieRole();
                    mr.MovieID   = m.MovieID;
                    mr.ActorID   = i;
                    mr.Actor     = principal.Actors.Where(x => x.ActorID == i).First();
                    mr.IsDeleted = false;
                    principal.MovieRoles.Add(mr);
                    principal.SaveChanges();
                }

                foreach (int i in model.DirectorsIDs)
                {
                    MovieDirection md = new MovieDirection();
                    md.MovieID    = m.MovieID;
                    md.DirectorID = i;
                    md.Director   = principal.Directors.Where(x => x.DirectorID == i).First();
                    md.IsDeleted  = false;
                    principal.MovieDirections.Add(md);
                    principal.SaveChanges();
                    model.Projection.Movie.MovieID = md.MovieID;
                }

                model.Movies = principal.Movies.Select(x => new SelectListItem
                {
                    Text  = x.OriginalName + "(" + x.MovieName + ")",
                    Value = x.MovieID.ToString()
                }).ToList();

                model.Movies = model.Movies.OrderByDescending(x => int.Parse(x.Value)).ToList();

                model.Projection.Movie.MovieRoles      = principal.MovieRoles.Where(x => x.MovieID == m.MovieID).ToList();
                model.Projection.Movie.MovieDirections = principal.MovieDirections.Where(x => x.MovieID == m.MovieID).ToList();

                model.IsCurrent = principal.Movies.Where(x => x.MovieID == m.MovieID).Select(x => x.IsCurrent).ToString();
                model.IsCurrent = (model.IsCurrent == "0") ? "NO" : "YES";

                return(PartialView("SetProjection", model));
            }

            if (ButtonType == "next")
            {
                return(PartialView("SetProjection", model));
            }

            //model.Projection.Movie.Genre.GenreName = genreName;
            //model.IsCurrent = (principal.Movies.Where(x => x.IsCurrent.ToString() == model.IsCurrent).ToString() == "0") ? "NO" : "YES";
            return(View("ShowTrailler", model));
        }
Пример #19
0
        public async Task AddRoleToMovieShouldReturnFalseIfProvidedArtistOrMovieNameIsInvalid(string movieName, string artistName, bool expectedResult)
        {
            var genre1 = new Genre
            {
                Name = "genre1"
            };
            var artist1 = new Artist
            {
                FullName  = "name1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            var artist2 = new Artist
            {
                FullName  = "name2",
                Biography = "biography2",
                BirthDate = DateTime.Parse("24 July 2019"),
                PhotoLink = "photo2",
            };
            var movie1 = new Movie
            {
                Name           = "movie1",
                ReleaseDate    = DateTime.Parse("24 July 2019"),
                Description    = "description1",
                Length         = 160,
                Genre          = genre1,
                Director       = artist1,
                CoverImageLink = "cover1",
                TrailerLink    = "trailer1",
            };
            var movieRole = new MovieRole
            {
                Movie           = movie1,
                Artist          = artist2,
                CharacterPlayed = "something",
            };
            await dbContext.Genres.AddAsync(genre1);

            await dbContext.Artists.AddAsync(artist1);

            await dbContext.Artists.AddAsync(artist2);

            await dbContext.Movies.AddAsync(movie1);

            await dbContext.MovieRoles.AddAsync(movieRole);

            await dbContext.SaveChangesAsync();

            var movieService = new MovieService(dbContext, reviewService.Object, watchlistService.Object, mapper);

            var input = new AddMovieRoleInputModel
            {
                Artist          = artistName,
                Movie           = movieName,
                CharacterPlayed = "character1",
            };

            var actualResult = await movieService.AddRoleToMovieAsync(input);

            Assert.True(actualResult == expectedResult);
        }
Пример #20
0
 public void Add(MovieRole newMovieRole)
 {
     db.MovieRole.Add(newMovieRole);
     db.SaveChanges();
 }