コード例 #1
0
        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));
        }
コード例 #2
0
        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());
        }