public MovieCommentResponse update(int commentId, MovieCommentRequest request) { var originalModel = _context.movieComments.FirstOrDefault(m => m.id.Equals(commentId)); var parsedModel = new MovieComment { description = request.description, updatedAt = request.updatedAt }; if (originalModel is null) { throw new Exception("Model not found"); } originalModel.description = parsedModel.description; _context.movieComments.Update(originalModel); _context.SaveChanges(); return(new MovieCommentResponse { id = originalModel.id, createdAt = originalModel.createdAt, description = originalModel.description, movieId = originalModel.movieId, updatedAt = originalModel.updatedAt, userId = originalModel.userId }); }
public MovieCommentResponse create(int movieId, MovieCommentRequest request) { var newModel = new MovieComment { movieId = movieId, description = request.description, userId = request.userId, }; _context.movieComments.Add(newModel); _context.SaveChanges(); return(new MovieCommentResponse { id = newModel.id, createdAt = newModel.createdAt, description = newModel.description, movieId = movieId, updatedAt = newModel.updatedAt, userId = newModel.userId }); }
public IActionResult PutMovieComment([FromRoute] int movieId, int commentId, [FromBody] MovieCommentRequest request) { return(Ok(_movieCommentService.update(commentId, request))); }
public IActionResult PostMovieComments([FromRoute] int movieId, [FromBody] MovieCommentRequest request) { return(StatusCode(201, _movieCommentService.create(movieId, request))); }