public async Task <bool> RemoveStartedMovie(StartedMovie startedMovie) { var deleteMovie = await StartedMovies.DeleteOneAsync(movie => (movie.TmdbId == startedMovie.TmdbId || movie.ImdbId == startedMovie.ImdbId) && movie.UserId == startedMovie.UserId); return(deleteMovie.DeletedCount > 0); }
public async Task <bool> MarkAsStartedMovie(StartedMovie movie) { await StartedMovies.InsertOneAsync(new StartedMovie { Date = movie.Date, HoursElapsed = movie.HoursElapsed, ImdbId = movie.ImdbId, MinutesElapsed = movie.MinutesElapsed, SecondsElapsed = movie.SecondsElapsed, TmdbId = movie.TmdbId, UserId = movie.UserId, WatchedPercentage = movie.WatchedPercentage }); return(true); }
public async Task <bool> UpdateStartedMovie(InternalStartedMovieUpdateRequest requestModel) { if (requestModel != null) { var mongoMovie = await _repo.GetMovieByTitle(requestModel.Title); if (mongoMovie != null) { //feltöltjük az üres ID-ket. requestModel.TmdbId = mongoMovie.TmdbId; requestModel.ImdbId = mongoMovie.ImdbId; //Megnézem, hogy láttuk -e már a filmet, mert ha igen akkor figyelmeztetem var isItSeen = await _repo.IsMovieSeen(mongoMovie, requestModel.UserId); if (!isItSeen) { //Létrehozom, hogy tudjuk jelölni mint elkezdett film és törölni is majd onnan. var startedMovie = new StartedMovie { Date = requestModel.Date, HoursElapsed = requestModel.HoursElapsed, ImdbId = requestModel.ImdbId, MinutesElapsed = requestModel.MinutesElapsed, SecondsElapsed = requestModel.SecondsElapsed, TmdbId = requestModel.TmdbId, UserId = requestModel.UserId, WatchedPercentage = requestModel.WatchedPercentage }; if (requestModel.WatchedPercentage < 95) { if (await IsMovieExistInMongoDb(requestModel.Title)) { //check if movie is started var isItStarted = await _repo.IsMovieStarted(requestModel.UserId, mongoMovie); if (isItStarted) { return(await _repo.UpdateStartedMovie(requestModel)); } return(await _repo.MarkAsStartedMovie(startedMovie)); } else { await Import(new InternalMovie { Title = requestModel.Title }); return(await _repo.UpdateStartedMovie(requestModel)); //throw new InternalException(650, "Movie not found in MONGODB."); } } //kitöröljük az elkezdett filmek közül await _repo.RemoveStartedMovie(startedMovie); //bejelöljük látottnak return(await _repo.MarkAsSeenMovie(mongoMovie, requestModel.UserId)); } throw new InternalException(606, "Movie already seen."); } throw new InternalException(650, "Movie not found by title in DB."); } return(false); }