/// <summary> /// Initializes a new instance of the Movie class. /// </summary> /// <param name="is3d">An indicator of whether or not the movie is 3D.</param> /// <param name="rating">The MPAA rating of the movie.</param> /// <param name="runtime">The runtime of the movie (in minutes).</param> /// <param name="title">The title of the movie.</param> public Movie(bool is3d, MovieRating rating, int runtime, string title) { this.is3d = is3d; this.rating = rating; this.runtime = runtime; this.title = title; }
//Button For Delete Movie (This button used for delete movie) private void DeleteMovie_Click(object sender, EventArgs e) { con.Open();// Connection Open comm = new SqlCommand("delete from Movies where MoviesId = " + MoviesID.Text + " ", con); try { comm.ExecuteNonQuery(); MessageBox.Show("Movie Deleted"); con.Close();// Connection Close ShowMoviesRecord(); MoviesID.Clear(); MovieTitle.Clear(); MovieRating.Clear(); MovieCopies.Clear(); MovieGenre.Clear(); MoviePlot.Clear(); MovieCost.Clear(); MovieReleaseDate.Clear(); } catch (Exception x) { MessageBox.Show("Movie Not Deleted" + x.Message); } finally { con.Close();// Connection Close } }
public IActionResult RateMovie(MovieViewModel viewModel) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var profile = _context.Profiles.FirstOrDefault(p => p.UserId == userId); if (profile is null) { return(RedirectToAction(nameof(Create))); } var rating = _context.MovieRatings.FirstOrDefault(r => r.MovieId == viewModel.Movie.id); if (rating is null) { rating = new MovieRating(); _context.MovieRatings.Add(rating); } rating.ProfileId = profile.Id; rating.MovieId = viewModel.Movie.id; rating.Rating = viewModel.MovieRating.Rating; rating.RatingDate = DateTime.Now; _context.SaveChanges(); return(RedirectToAction(nameof(Details), new { id = viewModel.Movie.id })); }
// Update Movie Button (This button used for Update movie details) private void UpdateMovie_Click(object sender, EventArgs e) { con.Open();// Connection Open comm = new SqlCommand("update Movies set MoviesId= '" + MoviesID.Text + "', MTitle= '" + MovieTitle.Text + "', MRating='" + MovieRating.Text + "', Mcopies='" + MovieCopies.Text + "', Mgenre='" + MovieGenre.Text + "', Mplot='" + MoviePlot.Text + "', MCost='" + MovieCost.Text + "', MRelaseDate='" + MovieReleaseDate.Text + "' where MoviesId = '" + MoviesID.Text + "'", con); try { comm.ExecuteNonQuery(); MessageBox.Show("Movie Updated"); con.Close();// Connection Close ShowMoviesRecord(); MoviesID.Clear(); MovieTitle.Clear(); MovieRating.Clear(); MovieCopies.Clear(); MovieGenre.Clear(); MoviePlot.Clear(); MovieCost.Clear(); MovieReleaseDate.Clear(); } catch (Exception) { MessageBox.Show("Movie Not Updated"); } finally { con.Close();// Connection Close } }
// Insert Movie Button (This button use for insert movie) private void InsertMovie_Click(object sender, EventArgs e) { con.Open();// Connection Open comm = new SqlCommand("insert into Movies values('" + MoviesID.Text + "','" + MovieTitle.Text + "','" + MovieRating.Text + "','" + MovieCopies.Text + "','" + MovieGenre.Text + "', '" + MoviePlot.Text + "', '" + MovieCost.Text + "', '" + MovieReleaseDate.Text + "')", con); try { comm.ExecuteNonQuery(); MessageBox.Show("Movie Saved"); con.Close();// Connection Close ShowMoviesRecord(); MoviesID.Clear(); MovieTitle.Clear(); MovieRating.Clear(); MovieCopies.Clear(); MovieGenre.Clear(); MoviePlot.Clear(); MovieCost.Clear(); MovieReleaseDate.Clear(); } catch (Exception) { MessageBox.Show("Movie Not Saved"); } finally { con.Close();// Connection Close } }
public void Should_UpdateExistingRatingInDatabase() { //arrange var existingRating = new Repo.MovieRating { MovieId = 1, UserId = 2, Rating = 3 }; var newRating = new MovieRating { MovieId = 1, UserId = 2, Rating = 4 }; InsertRating(existingRating); //act GetRepository().SaveRatingAsync(newRating); var ratingCount = 0; var firstRating = new Repo.MovieRating(); using (var context = GetContext()) { ratingCount = context.MovieRatingDbSet.Count(); firstRating = context.MovieRatingDbSet.First(); } //assert Assert.AreEqual(1, ratingCount); Assert.IsNotNull(firstRating); Assert.AreEqual(existingRating.MovieId, firstRating.MovieId); Assert.AreEqual(newRating.Rating, firstRating.Rating); Assert.AreEqual(existingRating.UserId, firstRating.UserId); }
async Task CompleteItem(MovieRating item) { item.Movie.Done = true; await movieRatingManager.SaveItemAsync(item); movieList.ItemsSource = await movieRatingManager.GetUnratedAsync(); }
public ActionResult <MovieRatingModel> AddOrUpdateRating(int movieId, [FromBody] UserRating rating) { try { var movieRating = Repository.GetMovieRatings(movieId).Where(r => r.UserId == rating.UserId).FirstOrDefault(); if (movieRating == null) { try { MovieRating m = Repository.AddRating(new MovieRating { MovieId = movieId, UserId = rating.UserId, Rating = rating.Rating }); return(CreatedAtAction("GetMovieRating", new { movieId = movieId, userId = movieRating.UserId }, ModelFactory.Create(m))); } catch { return(BadRequest("No such movie")); } } else { movieRating.Rating = rating.Rating; var result = ModelFactory.Create(Repository.UpdateRating(movieRating)); Repository.SaveAll(); return(Ok(result)); } } catch (Exception ex) { Logger.LogError($"AddOrUpdateRating: {ex}"); return(StatusCode(500, "Internal server error")); } }
public IEnumerable <MovieRating> ReadFile() { var movieRatings = new List <MovieRating>(); using (var reader = new StreamReader(@"C:\data\Ratings.csv")) { var headerLine = reader.ReadLine(); while (!reader.EndOfStream) { var values = reader.ReadLine().Split(';'); if (values.Length != 5) { throw new Exception(); } var movieRating = new MovieRating( values[0], values[1], values[2], values[3], values[4] ); movieRatings.Add(movieRating); } } return(movieRatings); }
public void Should_AddNewRatingToDatabase() { //arrange var rating = new MovieRating { MovieId = 1, Rating = 2, UserId = 3 }; //act GetRepository().SaveRatingAsync(rating); var ratingCount = 0; var firstRating = new Repo.MovieRating(); using (var context = GetContext()) { ratingCount = context.MovieRatingDbSet.Count(); firstRating = context.MovieRatingDbSet.First(); } //assert Assert.AreEqual(1, ratingCount); Assert.IsNotNull(firstRating); Assert.AreEqual(rating.MovieId, firstRating.MovieId); Assert.AreEqual(rating.Rating, firstRating.Rating); Assert.AreEqual(rating.UserId, firstRating.UserId); }
public ParentalControlsConfiguration(string filename) { this.filename = filename; maxGameRating = GameRating.AdultPlayers; maxMoveRating = MovieRating.NC17; timeLimit = new TimeSpan(2, 0, 0); }
public ActionResult NewM(MovieRating requestMovieRating) { try { List <MovieRating> mr = dmr.MovieRatings.Where(p => p.UserId.Equals(requestMovieRating.UserId) && p.MovieId == requestMovieRating.MovieId).ToList(); foreach (var a in mr) { dmr.MovieRatings.Remove(a); dmr.SaveChanges(); } MovieRating m = new MovieRating(); m.Value = requestMovieRating.Value; m.UserId = requestMovieRating.UserId; m.MovieId = requestMovieRating.MovieId; m.Movie = requestMovieRating.Movie; dmr.MovieRatings.Add(m); dmr.SaveChanges(); return(RedirectToAction("Show", "Movie", new { id = requestMovieRating.MovieId })); } catch (Exception e) { return(View()); } }
public IEnumerable <MovieRating> FindMovie(string title, string yearOfRelease, string genre) { List <MovieRating> movieRatings = new List <MovieRating>(); MovieRating movieRating = new MovieRating(); movieRating.Id = Guid.NewGuid(); movieRating.MovieId = Guid.NewGuid(); movieRating.Rating = 2; movieRating.UserId = Guid.NewGuid(); movieRating.Movie = new Movie(); movieRating.Movie.Id = movieRating.MovieId; movieRating.Movie.RunningTime = 90; movieRating.Movie.Title = "Lion King"; movieRating.Movie.YearOfRelease = 1998; movieRating.Movie.Genre = "Animation"; movieRatings.Add(movieRating); MovieRating movieRating1 = new MovieRating(); movieRating1.Id = Guid.NewGuid(); movieRating1.MovieId = Guid.NewGuid(); movieRating1.Rating = 5; movieRating1.UserId = Guid.NewGuid(); movieRating1.Movie = new Movie(); movieRating1.Movie.Id = movieRating1.MovieId; movieRating1.Movie.RunningTime = 90; movieRating1.Movie.Title = "Harry Potter"; movieRating1.Movie.YearOfRelease = 2001; movieRating1.Movie.Genre = "Children"; movieRatings.Add(movieRating1); return(movieRatings); }
public async Task Vote(MovieRating movieRating) { var userId = await authenticationStateService.GetCurrentUserId(); if (userId == null) { return; } var currentRating = await context.MovieRatings .FirstOrDefaultAsync(x => x.MovieId == movieRating.MovieId && x.UserId == userId); if (currentRating == null) { movieRating.UserId = userId; movieRating.RatingDate = DateTime.Today; context.Add(movieRating); await context.SaveChangesAsync(); } else { currentRating.Rate = movieRating.Rate; await context.SaveChangesAsync(); } }
public async Task <ActionResult <MovieRating> > PostMovieRating(MovieRating movieRating) { _context.MovieRating.Add(movieRating); await _context.SaveChangesAsync(); return(CreatedAtAction("GetMovieRating", new { id = movieRating.MovieRatingId }, movieRating)); }
protected void btnUpdateRate_Click(object sender, EventArgs e) { setClient(); string user = txtUserId.Text; MovieRating movieRating = new MovieRating() { MovieId = txtMovieId.Text, UserId = txtUsrId.Text, Rating = txtRate.Text }; //HTTP GET var responseTask = client.PutAsJsonAsync("UpdateMovieRating", movieRating); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { message.Text = result.StatusCode.ToString(); } else { message.Text = result.ReasonPhrase + result.StatusCode; } }
public async Task <IActionResult> Post([FromBody] MovieRating movieRating) { var validationResult = await _ratingService.ValidateMovieRatingAsync(movieRating); switch (validationResult) { case MovieRatingSaveValidationResults.OK: if (await _ratingService.SaveRatingAsync(movieRating)) { return(Ok()); } else { return(BadRequest("couldn't save rating")); } case MovieRatingSaveValidationResults.NullRating: case MovieRatingSaveValidationResults.InvalidMovieId: case MovieRatingSaveValidationResults.InvalidUserId: return(BadRequest(validationResult.ToString())); case MovieRatingSaveValidationResults.MovieNotfound: case MovieRatingSaveValidationResults.UserNotFound: return(NotFound(validationResult.ToString())); } return(BadRequest("unknown validation failure")); }
private void Seed() { using (var context = new ApplicationDBContext(ContextOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var MovieRatingEntry = new MovieRating(); MovieRatingEntry.MovieID = 2; MovieRatingEntry.Rating = 6; context.Add(MovieRatingEntry); context.SaveChanges(); //var one = new Item("ItemOne"); //one.AddTag("Tag11"); //one.AddTag("Tag12"); //one.AddTag("Tag13"); //var two = new Item("ItemTwo"); //var three = new Item("ItemThree"); //three.AddTag("Tag31"); //three.AddTag("Tag31"); //three.AddTag("Tag31"); //three.AddTag("Tag32"); //three.AddTag("Tag32"); //context.AddRange(one, two, three); //context.SaveChanges(); } }
private void LoadModel(MovieRating testInput) { // Create MLContext MLContext mlContext = new MLContext(); DataViewSchema modelSchema; // Load trained model ITransformer trainedModel = mlContext.Model.Load(@"E:\Development\IA\Recomendador\Model\MovieRecommenderModel.zip", out modelSchema); var predictionEngine = mlContext.Model.CreatePredictionEngine <MovieRating, MovieRatingPrediction>(trainedModel); var movieRatingPrediction = predictionEngine.Predict(testInput); if (Math.Round(movieRatingPrediction.Score, 1) > 3.5) { MessageBox.Show("Movie " + testInput.movieId + " is recommended for user " + testInput.userId); } else { MessageBox.Show("Movie " + testInput.movieId + " is not recommended for user " + testInput.userId); } // MessageBox.Show("Peli" + movieRatingPrediction.Label + " Score :" + movieRatingPrediction.Score.ToString()); }
public async Task <IActionResult> PutMovieRating(int id, MovieRating movieRating) { if (id != movieRating.MovieRatingId) { return(BadRequest()); } _context.Entry(movieRating).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieRatingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void TestIfNoReviews() { IMovieRating mr = new MovieRating(MemoryDB); List <MovieReview> list = mr.AllReviewsFromReviewer(-1); Assert.AreEqual(0, list.Count); }
// Use model for single prediction public static void UseModelForSinglePrediction(MLContext mlContext, ITransformer model) { // <SnippetPredictionEngine> Console.WriteLine("=============== Making a prediction ==============="); var predictionEngine = mlContext.Model.CreatePredictionEngine <MovieRating, MovieRatingPrediction>(model); // </SnippetPredictionEngine> // Create test input & make single prediction // <SnippetMakeSinglePrediction> var testInput = new MovieRating { userId = 6, movieId = 10 }; var movieRatingPrediction = predictionEngine.Predict(testInput); // </SnippetMakeSinglePrediction> // <SnippetPrintResults> if (Math.Round(movieRatingPrediction.Score, 1) > 3.5) { Console.WriteLine("Movie " + testInput.movieId + " is recommended for user " + testInput.userId); } else { Console.WriteLine("Movie " + testInput.movieId + " is not recommended for user " + testInput.userId); } // </SnippetPrintResults> }
public async Task <MovieRating> AddOrUpdateRatingAsync(int movieId, int userId, decimal rating) { var movie = _context.Movies.FirstOrDefault(x => x.MovieId == movieId); if (movie == null) { return(null); //Invalid movie } var user = _context.Users.FirstOrDefault(x => x.UserId == userId); if (user == null) { return(null); //Invalid user } var movieRating = _context.Ratings.FirstOrDefault(x => x.MovieId == movieId && x.UserId == userId); if (movieRating == null) { movieRating = new MovieRating() { MovieId = movieId, UserId = userId }; _context.Ratings.Add(movieRating); } movieRating.Rating = rating; await _context.SaveChangesAsync().ConfigureAwait(false); return(movieRating); }
public void ShouldReturn_ExpectedActionResultAfter_Saving(bool saved) { //arrange var rating = new MovieRating { MovieId = 1, Rating = 2, UserId = 3 }; MockRatingService.Setup(s => s.ValidateMovieRatingAsync(rating)).Returns(Task.FromResult(MovieRatingSaveValidationResults.OK)); MockRatingService.Setup(s => s.SaveRatingAsync(rating)).Returns(Task.FromResult(saved)); //act var asyncResult = GetController().Post(rating); //assert var result = asyncResult.Result; if (saved) { Assert.IsInstanceOf <OkResult>(result); } else { Assert.IsInstanceOf <BadRequestObjectResult>(result); } }
public bool PostMyRating(UserRatingDto rating) { if (_context.Users.Any(u => u.Id == rating.UserId) && _context.Movies.Any(m => m.Id == rating.MovieId)) { try { var ratingDetails = new MovieRating() { Rating = rating.Rating, UserId = rating.UserId, MovieId = rating.MovieId }; var userRating = _context.MovieRatings.SingleOrDefault(r => r.MovieId == rating.MovieId && r.UserId == rating.UserId); if (userRating == null) { _context.MovieRatings.Add(ratingDetails); } else { userRating.Rating = rating.Rating; } _context.SaveChanges(); return(true); } catch { return(false); } } return(false); }
static void AddMovie() { int movieID = ConsoleHelpers.ReadInt("Enter movie ID: ", 1, 999999999); string movieTitle = ConsoleHelpers.ReadString("Enter movie title: ", 1); string moviePublisher = ConsoleHelpers.ReadString("Enter movie producer/publisher: ", 1); string movieCreator = ConsoleHelpers.ReadString("Enter movie screenwriter: ", 1); DateTime moviePublishDate = ConsoleHelpers.ReadDate("Enter release date: ", DateTime.Parse("1/1/1878"), DateTime.Now); int movieRunLength = ConsoleHelpers.ReadInt("Enter run length: ", 1); //Show movie ratings and prompt user to select Console.WriteLine("Movie rating:"); foreach (var rating in Enum.GetValues(typeof(MovieRating))) { Console.WriteLine($"\t[{(int)rating}] - {rating}"); } MovieRating movieRating = (MovieRating)ConsoleHelpers.ReadInt("Value: ", 0, 5); // try to create a new Movie object and add to MediaDb list try { Movie myMovie = new Movie(movieID, movieTitle, moviePublisher, movieCreator, moviePublishDate, movieRunLength, movieRating); MediaDb.Add(myMovie); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); return; } catch (Exception ex) { Console.WriteLine($"An unknow error has occured: {ex.Message}"); } }
public void Update(MovieRating updatedRating) { var entity = db.Ratings.Attach(updatedRating); entity.State = EntityState.Modified; db.SaveChanges(); }
public async Task <ActionResult> Rate(MovieRating movieRating) { var user = await userManager.FindByEmailAsync(HttpContext.User.Identity.Name); var userId = user.Id; var currentRating = await context.MovieRatings .FirstOrDefaultAsync(x => x.MovieId == movieRating.MovieId && x.UserId == userId); if (currentRating == null) { movieRating.UserId = userId; movieRating.RatingDate = DateTime.Today; context.Add(movieRating); await context.SaveChangesAsync(); } else { currentRating.Rate = movieRating.Rate; await context.SaveChangesAsync(); } return(NoContent()); }
private void button1_Click(object sender, System.EventArgs e) { var testInput = new MovieRating { userId = int.Parse(this.textBoxUserId.Text), movieId = float.Parse(this.textBoxMovieId.Text) }; this.LoadModel(testInput); }
public void Test_AllReviewsFromReviewer() { var mr = new MovieRating(MemoryDB); int numberOfReviews = mr.AllReviewsFromReviewer(1).Count; Assert.AreEqual(5, numberOfReviews); }
public Movie(int id, string title, int year, string image, MovieRating rating) { this.MovieId = id; this.Title = title; this.YearReleased = year; this.ImageUrl = image; this.Rating = rating; }
public Movie(string title, string director, string mainActor, string movieMaker, int year, MovieRating rating) { Title = title; Director = director; MainActor = mainActor; MovieMaker = movieMaker; Year = year; Rating = rating; }