public async Task <ActionResult <UserScore> > PostUserScore(SimpleUserScore simpleScore) { UserScore userScore = new UserScore(); userScore.movieId = simpleScore.movieId; userScore.userId = simpleScore.userId; userScore.score = simpleScore.score; userScore.user = await _context.Users.FindAsync(simpleScore.userId); userScore.movie = await _context.Movies.FindAsync(simpleScore.movieId); _context.UserScores.Add(userScore); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUserScore", new { id = userScore.id }, userScore)); }
public async Task <IActionResult> PutUserScore(int id, SimpleUserScore simpleScore) { UserScore userScore = new UserScore(); userScore.id = simpleScore.id; userScore.movieId = simpleScore.movieId; userScore.userId = simpleScore.userId; userScore.score = simpleScore.score; userScore.user = await _context.Users.FindAsync(simpleScore.userId); userScore.movie = await _context.Movies.FindAsync(simpleScore.movieId); if (id != userScore.id) { return(BadRequest()); } _context.Entry(userScore).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserScoreExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }