public async Task <Trivia> CreateTriviaFromRequest(AddTriviaRequest request) { var movie = await _dataContext.Movies.FirstOrDefaultAsync(x => x.MovieGuid.ToString() == request.MovieGuid); var studio = await _dataContext.Studios.FirstOrDefaultAsync(x => x.StudioGuid.ToString() == request.StudioGuid); var trivia = new Trivia { TriviaGuid = Guid.NewGuid(), MovieId = movie.Id, StudioId = studio.Id, TriviaText = request.TriviaText }; return(trivia); }
public async Task <IActionResult> Create([FromRoute] AddTriviaRequest request) { var trivia = await _triviaService.CreateTriviaFromRequest(request); var success = await _triviaService.AddTriviaAsync(trivia); if (!success) { return(NotFound()); } var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; var locationUri = baseUrl + "/" + ApiRoutes.Ratings.Get.Replace("{Id}", trivia.TriviaGuid.ToString()); var response = await _triviaService.CreateTriviaResponse(trivia); return(Created(locationUri, response)); }