public async Task <MovieTagsDomainModel> AddMovieTag(MovieTagsDomainModel newMovieTag) { MovieTag movieTagToCreate = new MovieTag() { MovieId = newMovieTag.MovieId, Tagid = newMovieTag.TagId }; var data = _movieTagsRepository.Insert(movieTagToCreate); if (data == null) { return(null); } _movieTagsRepository.Save(); MovieTagsDomainModel domainModel = new MovieTagsDomainModel() { MovieId = data.MovieId, TagId = data.Tagid }; return(domainModel); }
/// <summary> /// Updates a User's existing Movie Tag in the database. /// </summary> /// <param name="movieTagUser"></param> /// <returns></returns> public void UpdateMovieTagUser(MovieTagUser movieTagUser) { var movieTag = GetMovieTag(movieTagUser.ImdbId, movieTagUser.TagName); if (movieTag == null) { movieTag = new MovieTag(); movieTag.ImdbId = movieTagUser.ImdbId; movieTag.TagName = movieTagUser.TagName; movieTag.VoteSum = 0; _dbContext.MovieTags.Add(movieTag); } bool isUpvote = movieTagUser.IsUpvote ?? true; if (isUpvote) { if (movieTag.VoteSum < int.MaxValue) { movieTag.VoteSum += 1; } } else { if (movieTag.VoteSum > int.MinValue) { movieTag.VoteSum -= 1; } } _dbContext.MovieTagUsers.Update(movieTagUser); _dbContext.SaveChanges(); }
private MovieTag CopyMovieInfos(MovieTag movieTag, Movie movie) { movieTag.Title = movie.Title; movieTag.IMDB_ID = movie.ImdbId; movieTag.TMDB_ID = movie.Id.ToString(); MovieCollection collection = movie.Collection; movieTag.CollectionTitle = collection != null ? collection.Name : null; movieTag.ReleaseDate = movie.ReleaseDate.HasValue ? movie.ReleaseDate.Value.ToString("yyyy-MM-dd") : null; movieTag.Overview = movie.Overview; movieTag.Tagline = movie.Tagline; //todo: implement certification //movieTag.Certification = movie. movieTag.Genres = movie.Genres.Select(g => g.Name).ToList().AsReadOnly(); MovieCasts casts = movieDbApi.GetCastCrew(movie.Id); if (casts == null) { return(movieTag); } movieTag.Actors = casts.Cast.Select(p => p.Name).ToList().AsReadOnly(); movieTag.Directors = casts.Crew.Where(p => p.Job == "Director").Select(p => p.Name).ToList().AsReadOnly(); movieTag.Writers = casts.Crew.Where(p => p.Job == "Author").Select(p => p.Name).ToList().AsReadOnly(); return(movieTag); }
private void UpdateGUI(MovieTag tag = null) { ClearGUI(); if (ReferenceEquals(tag, null)) { return; } // Recommended for identification Title.Value = tag.Title; IMDB_ID.Value = tag.IMDB_ID; TMDB_ID.Value = tag.TMDB_ID; // additional collection infos CollectionTitle.Value = tag.CollectionTitle; CollectionIndex.Value = tag.CollectionIndex; CollectionKeywords.Value = tag.CollectionKeywords; // additional episode infos ReleaseDate.Value = tag.ReleaseDate; Overview.Value = tag.Overview; Tagline.Value = tag.Tagline; Certification.Value = tag.Certification; Genres.Value = tag.Genres; Actors.Value = tag.Actors; Directors.Value = tag.Directors; Writers.Value = tag.Writers; MovieKeywords.Value = tag.MovieKeywords; }
public MovieTag Delete(object id) { MovieTag movieTag = _cinemaContext.MovieTags.Find(id); var result = _cinemaContext.MovieTags.Remove(movieTag).Entity; return(result); }
public void TestInitialize() { _movieTag = new MovieTag { MovieId = Guid.NewGuid(), Tagid = 1, Movie = new Movie(), Tag = new Tag() }; _movieTagDomainModel = new MovieTagsDomainModel { MovieId = _movieTag.MovieId, TagId = 1, MovieTitle = "NazivFilma", TagName = "NazivTaga" }; List <MovieTag> movieTagsList = new List <MovieTag>(); movieTagsList.Add(_movieTag); IEnumerable <MovieTag> movieTags = movieTagsList; Task <IEnumerable <MovieTag> > responseTask = Task.FromResult(movieTags); _mockMovieTagsRepostitory = new Mock <IMovieTagsRepository>(); }
public ActionResult Details(int movie_ID, List <String> tags, bool anon) { //if (true) { Tools.TraceLine("Looking to add the tags {0}, to movie id {1}", tags[0], movie_ID); MovieDbContext db = new MovieDbContext(); Movie taggedMovie = db.Movies.Find(movie_ID); MovieTag newTag = new MovieTag(); //break the tags down by comma delimeter List <String> seperatedtags = UserInput.DeliminateStrings(tags); seperatedtags = UserInput.StripWhiteSpace(seperatedtags); seperatedtags = UserInput.SanitizeSpecialCharacters(seperatedtags); foreach (string tag in seperatedtags) { //JB note: not sure if FoD() here return null if there's nothing, // I think it return a new Tag() empty which'll mean that // it's never gonna hit null. Not sure though. //JT Note: I'm pretty damn sure I tested this and it works, however you //are probably right and we shoudl switch it to somethign a little less error prone. var tagExists = db.MovieTags.FirstOrDefault(t => t.Name == tag); if (tagExists == null) { //tag doesn't exist, so create it newTag.Name = tag; db.MovieTags.Add(newTag); db.SaveChanges(); } else { //otherwise select the MovieTag where the names match and use that. newTag = db.MovieTags.First(t => t.Name == tag); } UserToMovieToTags UtMtT = new UserToMovieToTags(); UtMtT.TagId = newTag.TagId; UtMtT.UserID = WebSecurity.CurrentUserId; UtMtT.movie_ID = movie_ID; db.UserToMovieToTags.Add(UtMtT); db.SaveChanges(); UtMtTisAnon anonTags = new UtMtTisAnon(); anonTags.UtMtT_ID = UtMtT.UtMtY_ID; anonTags.IsAnon = anon; db.UtMtTisAnon.Add(anonTags); db.SaveChanges(); Tools.TraceLine("added tag {0} to movie_id {1}", UtMtT.TagId, movie_ID); } int id = movie_ID; return(RedirectToAction("Details", new { movie_ID = id })); }
public MovieTag Update(MovieTag obj) { var updatedEntry = _cinemaContext.MovieTags.Attach(obj); _cinemaContext.Entry(obj).State = EntityState.Modified; return(updatedEntry.Entity); }
public async Task <MovieTag> Add(MovieTag entity) { await _context.MovieTags.AddAsync(entity); await _context.SaveChangesAsync(); if (entity == null) { throw new InvalidDataException("Жанр фильма не создан"); } return(entity); }
public async Task <bool> Update(int id, MovieTag entity) { var movieTag = await _context.MovieTags.FindAsync(id); if (movieTag == null) { throw new MovieTagNotFoundException(); } movieTag.Name = entity.Name; _context.MovieTags.Update(movieTag); return(await _context.SaveChangesAsync() > 0); }
public void AddMovieTag() { var mockSet = new Mock <DbSet <MovieTag> >(); var movieTag = new MovieTag(); var mockContext = new Mock <FilmCatalogContext>(); mockContext.Setup(m => m.MovieTags).Returns(mockSet.Object); var service = new MovieTagController(mockContext.Object); service.AddMovieTag(movieTag); mockSet.Verify(m => m.Add(It.IsAny <MovieTag>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
public MovieTag UpdateTags(MovieTag movieTag) { if (movieDbApi == null) { movieDbApi = new MovieDbApiV3(API_KEY, null); } Movie movie; string imdb = movieTag.IMDB_ID; if (!string.IsNullOrEmpty(imdb)) { movie = movieDbApi.GetMovie(imdb, App.Config.SelectedTMDBLanguageValue); if (movie != null) { return(CopyMovieInfos(movieTag, movie)); } MessageBox.Show("TMDB lookup by IMDB id failed."); } string name = movieTag.Title; if (string.IsNullOrEmpty(imdb) && string.IsNullOrEmpty(name)) { MessageBox.Show("TMDB lookup needs atleast IMDB id or movie title."); return(movieTag); } MovieSearchResult searchResult = SearchMovie(name); if (searchResult == null) { return(movieTag); } movie = movieDbApi.GetMovie(searchResult.Id, App.Config.SelectedTMDBLanguageValue); if (movie == null) { return(movieTag); } return(CopyMovieInfos(movieTag, movie)); }
public void MovieTagsService_AddMovieTag_RepositoryReturnsNull_ReturnNull() { //Arrange MovieTag movieTagNull = null; MovieTagService movieTagService = new MovieTagService(_mockMovieTagsRepostitory.Object); _mockMovieTagsRepostitory.Setup(x => x.Insert(It.IsAny <MovieTag>())).Returns(movieTagNull); //Act var result = movieTagService.AddMovieTag(_movieTagDomainModel).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNull(result); }
public void MovieTagsService_DeleteByMovieIdTagId_RepositoryReturnsNull_ReturnsNull() { //Arrange MovieTag movieTagNull = null; Task <MovieTag> movieTag = Task.FromResult(movieTagNull); MovieTagService movieTagService = new MovieTagService(_mockMovieTagsRepostitory.Object); _mockMovieTagsRepostitory.Setup(x => x.DeleteById(It.IsAny <Guid>(), It.IsAny <int>())).Returns(movieTag); //Act var result = movieTagService.DeleteByMovieIdTagId(_movieTag.MovieId, _movieTag.Tagid).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNull(result); }
public IActionResult AddMovieTag([FromBody] NewMovieTag newMovieTag) { //tag不存在 if (!service.CheckTagExist(newMovieTag.TagName)) { return(Ok(new { Success = false, msg = "Tag doesn't exist" })); } else { //tag存在且未被添加到该电影 if (!service.CheckMovieTagExist(newMovieTag.MovieID, newMovieTag.TagName)) { var movietag = new MovieTag { m_id = newMovieTag.MovieID, tag_name = newMovieTag.TagName }; context.MovieTag.Add(movietag); context.SaveChanges(); return(Ok(new { Success = true, msg = "MovieTag added" })); } //该电影已经有了这个tag else { return(Ok(new { Success = false, msg = "Movie already have this tag" })); } } }
private async Task SaveMovies(IEnumerable <TMDB.DiscoveredMovie> discoveredMovies) { foreach (var discoveredMovie in discoveredMovies) { var imageUrl = discoveredMovie.Poster_Path is null ? "" : $"https://image.tmdb.org/t/p/w200{discoveredMovie.Poster_Path}"; var movie = new Movie() { Id = discoveredMovie.Id, AverageRating = discoveredMovie.Vote_Average, Description = discoveredMovie.Overview, ImageUrl = imageUrl, Title = discoveredMovie.Title, Date = discoveredMovie.Release_Date }; _context.Movies.Attach(movie); await _context.Movies.AddAsync(movie); foreach (var tagId in discoveredMovie.Genre_Ids) { var movieTag = new MovieTag() { MovieId = discoveredMovie.Id, TagId = tagId }; try { _context.MovieTags.Attach(movieTag); await _context.MovieTags.AddAsync(movieTag); } catch { } } await _context.SaveChangesAsync(); } }
/// <summary> /// Adds a User's Tag Vote for a Movie to the database /// and increments the MovieTag's VoteSum. /// Adds the Tag to the database if it does not exist. /// Adds the MovieTag to the database if it does not /// exist. /// </summary> /// <param name="movieTagUser"></param> /// <returns></returns> public void AddMovieTagUser(MovieTagUser movieTagUser) { if (!TagExists(movieTagUser.TagName)) { Tag tag = new Tag(); tag.TagName = movieTagUser.TagName; tag.IsBanned = false; _dbContext.Tags.Add(tag); } var movieTag = GetMovieTag(movieTagUser.ImdbId, movieTagUser.TagName); if (movieTag == null) { movieTag = new MovieTag(); movieTag.ImdbId = movieTagUser.ImdbId; movieTag.TagName = movieTagUser.TagName; movieTag.VoteSum = 0; _dbContext.MovieTags.Add(movieTag); } bool isUpvote = movieTagUser.IsUpvote ?? true; if (isUpvote) { if (movieTag.VoteSum < int.MaxValue) { movieTag.VoteSum += 1; } } else { if (movieTag.VoteSum > int.MinValue) { movieTag.VoteSum -= 1; } } _dbContext.MovieTagUsers.Add(movieTagUser); _dbContext.SaveChanges(); }
private MovieTag UpdateTagFromGUI(MovieTag tag) { // Recommended for identification tag.Title = Title.Value; tag.IMDB_ID = IMDB_ID.Value; tag.TMDB_ID = TMDB_ID.Value; // additional collection infos tag.CollectionTitle = CollectionTitle.Value; tag.CollectionIndex = CollectionIndex.Value; tag.CollectionKeywords = CollectionKeywords.Value; // additional episode infos tag.ReleaseDate = ReleaseDate.Value; tag.Overview = Overview.Value; tag.Tagline = Tagline.Value; tag.Certification = Certification.Value; tag.Genres = Genres.Value; tag.Actors = Actors.Value; tag.Directors = Directors.Value; tag.Writers = Writers.Value; tag.MovieKeywords = MovieKeywords.Value; return(tag); }
public MovieTag Update(MovieTag obj) { throw new NotImplementedException(); }
/// <summary> /// Adds the provided Movie and all associated information (Actors, Directors, Genres, /// Languages, Tags) to the provided context. Assumes the all Movie information is /// unique, GetRandomMovie() provides a Movie with information that is astronomically /// unlikely to repeat. /// </summary> /// <param name="context"></param> /// <param name="movieDTO"></param> public static void AddMovieDTOToDatabase(Cinephiliacs_MovieContext context, MovieDTO movieDTO) { Movie movie = new Movie(); movie.ImdbId = movieDTO.ImdbId; movie.Title = movieDTO.Title; Rating newRating = new Rating(); newRating.RatingName = movieDTO.RatingName; context.Ratings.Add(newRating); context.SaveChanges(); movie.RatingId = context.Ratings.FirstOrDefault(r => r.RatingName == movieDTO.RatingName).RatingId; movie.ReleaseDate = DateTime.ParseExact(movieDTO.ReleaseDate, "yyyy-MM-dd", CultureInfo.InvariantCulture); movie.IsReleased = true; movie.ReleaseCountry = movieDTO.ReleaseCountry; movie.RuntimeMinutes = movieDTO.RuntimeMinutes; movie.Plot = movieDTO.Plot; movie.PosterUrl = movieDTO.PosterURL; context.Movies.Add(movie); context.SaveChanges(); foreach (var movieActorName in movieDTO.MovieActors) { Actor newActor = new Actor(); newActor.ActorName = movieActorName; context.Actors.Add(newActor); context.SaveChanges(); Actor actor = context.Actors.FirstOrDefault(a => a.ActorName == movieActorName); MovieActor movieActor = new MovieActor(); movieActor.ImdbId = movieDTO.ImdbId; movieActor.ActorId = actor.ActorId; context.MovieActors.Add(movieActor); context.SaveChanges(); } foreach (var movieDirectorName in movieDTO.MovieDirectors) { Director newDirector = new Director(); newDirector.DirectorName = movieDirectorName; context.Directors.Add(newDirector); context.SaveChanges(); Director director = context.Directors.FirstOrDefault(d => d.DirectorName == movieDirectorName); MovieDirector movieDirector = new MovieDirector(); movieDirector.ImdbId = movieDTO.ImdbId; movieDirector.DirectorId = director.DirectorId; context.MovieDirectors.Add(movieDirector); context.SaveChanges(); } foreach (var movieGenreName in movieDTO.MovieGenres) { Genre newGenre = new Genre(); newGenre.GenreName = movieGenreName; context.Genres.Add(newGenre); context.SaveChanges(); Genre genre = context.Genres.FirstOrDefault(a => a.GenreName == movieGenreName); MovieGenre movieGenre = new MovieGenre(); movieGenre.ImdbId = movieDTO.ImdbId; movieGenre.GenreId = genre.GenreId; context.MovieGenres.Add(movieGenre); context.SaveChanges(); } foreach (var movieLanguageName in movieDTO.MovieLanguages) { Language newLanguage = new Language(); newLanguage.LanguageName = movieLanguageName; context.Languages.Add(newLanguage); context.SaveChanges(); Language language = context.Languages.FirstOrDefault(a => a.LanguageName == movieLanguageName); MovieLanguage movieLanguage = new MovieLanguage(); movieLanguage.ImdbId = movieDTO.ImdbId; movieLanguage.LanguageId = language.LanguageId; context.MovieLanguages.Add(movieLanguage); context.SaveChanges(); } foreach (var movieTagName in movieDTO.MovieTags) { Tag newTag = new Tag(); newTag.TagName = movieTagName; newTag.IsBanned = false; context.Tags.Add(newTag); context.SaveChanges(); MovieTag movieTag = new MovieTag(); movieTag.ImdbId = movieDTO.ImdbId; movieTag.TagName = movieTagName; movieTag.VoteSum = 1; context.MovieTags.Add(movieTag); context.SaveChanges(); } }
private async Task CreateMovieTagAsync(MovieTag movieTagToCreate) { var sql = @"INSERT INTO [MovieTag] ([MovieId], [TagId]) VALUES(@MovieId, @TagId)"; await Session.Connection.ExecuteAsync(sql, movieTagToCreate); }
public void InsertBlogTag(MovieTag blogTag) { db.MovieTags.Add(blogTag); }
public async Task <MovieDomainModel> AddMovie(MovieDomainModel newMovie, MovieCreateTagDomainModel movieCreateTagDomainModel) { Movie movieToCreate = new Movie() { Title = newMovie.Title, Current = newMovie.Current, Year = newMovie.Year, Rating = newMovie.Rating }; var data = _moviesRepository.Insert(movieToCreate); if (data == null) { return(null); } if (movieCreateTagDomainModel.Duration > 0) { var durationIntToString = movieCreateTagDomainModel.Duration.ToString(); Tag durationTag = new Tag { Name = durationIntToString, Type = "duration", }; var newTagAdded = _tagRepository.Insert(durationTag); MovieTag movieTag = new MovieTag() { MovieId = data.Id, Tag = newTagAdded }; _movieTagsRepository.Insert(movieTag); } if (movieCreateTagDomainModel.tagsForMovieToAdd != null && movieCreateTagDomainModel.tagsForMovieToAdd.Count > 0) { foreach (var item in movieCreateTagDomainModel.tagsForMovieToAdd) { var findTag = _tagRepository.GetByIdName(item); if (findTag != null) { MovieTag moviTagToAdd = new MovieTag { MovieId = data.Id, TagId = findTag.Id }; _movieTagsRepository.Insert(moviTagToAdd); } } } _moviesRepository.Save(); MovieDomainModel domainModel = new MovieDomainModel() { Id = data.Id, Title = data.Title, Current = data.Current, Year = data.Year, Rating = data.Rating ?? 0 }; return(domainModel); }
public void DeleteBlogTag(MovieTag blogTag) { db.MovieTags.Remove(blogTag); }
public MovieTag Insert(MovieTag obj) { return(_cinemaContext.MovieTags.Add(obj).Entity); }
public MovieTag Insert(MovieTag obj) { var data = _cinemaContext.MovieTags.Add(obj).Entity; return(data); }
private MovieTagViewModel GetMapperMovieTagToMovieTagViewModel(MovieTag entity) { return(_mapper.Map <MovieTagViewModel>(entity)); }
public void AddMovieTag(MovieTag movieTag) { context.MovieTags.Add(movieTag); context.SaveChanges(); }
public void TestInitialize() { _movie = new Data.Movie { Id = Guid.NewGuid(), Current = true, Rating = 2, Title = "TitleMovie", MovieTags = new List <MovieTag>(), Projections = new List <Projection>(), Year = 1895 }; _movieTag = new MovieTag { Id = Guid.NewGuid(), MovieId = _movie.Id, TagId = 1, Tag = new Tag { Id = 1, Name = "NameTag", Type = "Type" } }; _movie.MovieTags.Add(_movieTag); _movie.Projections.Add(new Projection { AuditoriumId = 1, DateTime = DateTime.Now, Id = Guid.NewGuid(), MovieId = _movie.Id }); _movieDomainModel = new MovieDomainModel { Current = true, Id = _movie.Id, Rating = 2, Title = "TitleMovie", Year = 1895 }; _deletedMovieModelSuccess = new DeleteMovieModel { ErrorMessage = null, IsSuccessful = true, MovieDomainModel = _movieDomainModel }; _projection = new Projection { Id = Guid.NewGuid(), MovieId = _movie.Id, AuditoriumId = 1, DateTime = DateTime.Now.AddDays(1) }; _projections = new List <Projection>(); _projections.Add(_projection); moviesModelsList = new List <Movie>(); moviesModelsList.Add(_movie); _movieTagsList = new List <MovieTag>(); _movieTagsList.Add(_movieTag); _movieDomainModels = new List <MovieDomainModel>(); _movieDomainModels.Add(_movieDomainModel); _mockMovieTagsRepository = new Mock <IMovieTagsRepository>(); _mockTagRepository = new Mock <ITagRepository>(); _mockProjectionsRepository = new Mock <IProjectionsRepository>(); _mockMovieTagsRepository = new Mock <IMovieTagsRepository>(); _mockTicketRepository = new Mock <ITicketRepository>(); }