public void AddOrUpdateRating_AddUserRating_Success() { var user1 = new User { Id = 101 }; userContext.Add(user1); userContext.SaveChanges(); var movieTitle = "Frozen 2"; var movieId = 234; var movie = new Movie { Title = "Frozen 2", Id = movieId }; movieContext.Movies.Add(movie); movieContext.SaveChanges(); var result = movieService.AddOrUpdateRating(movie.Id, user1.Id, 5M); Assert.IsTrue(result); }
public IActionResult Post([FromBody] MovieRatingRequestModel model) { if (!(model.Score >= 1M && model.Score <= 5M)) { return(BadRequest()); } var success = movieService.AddOrUpdateRating(model.MovieId, model.UserId, model.Score); if (!success) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> Post([FromBody] UserMovieRatingDto dto) { if (dto == null) { return(BadRequest()); } if (dto.MovieID == 0 || dto.UserID == 0) { return(BadRequest()); } var result = await Task.Run(() => _menuService.AddOrUpdateRating(dto)); if (result != null && result.ID > 0) { return(Json(result)); } return(BadRequest()); }