public async Task <IActionResult> Create([FromBody] CreateReviewRequestDto dto) { var reviewToCreate = _mapper.Map <Review>(dto); var criteria = await _criteriasRepository.GetCriteriaByName(dto.CriteriaName); if (criteria == null) { criteria = new Criteria { Name = dto.CriteriaName }; _criteriasRepository.Create(criteria); } reviewToCreate.Criteria = criteria; _reviewsRepository.Create(reviewToCreate); if (await _reviewsRepository.SaveAllChangesAsync()) { var reviewFromDb = await _reviewsRepository.GetByIdAsync(reviewToCreate.Id); var droToReturn = _mapper.Map <ReviewDto>(reviewFromDb); return(CreatedAtRoute(nameof(GetReview), new { id = reviewToCreate.Id }, droToReturn)); } return(BadRequest("Could not create a review.")); }