public async Task <ActionResult> CreateRating([FromBody] CompositionRatingViewModel rating) { try { if (rating == null) { logger.LogError($"Rating object sent from client is null"); return(BadRequest("Rating object is null")); } if (rating.Rating > 5 || rating.Rating < 0) { return(BadRequest("Rating out of bounds")); } await ratingsAdapter.AddRating(rating).ConfigureAwait(false); logger.LogInformation($"Rating for composition with id: {rating.CompositionId} is successfully added"); return(Ok()); } catch (Exception ex) { logger.LogError($"Something went wrong inside CreateRating action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public async Task AddRating(CompositionRatingViewModel rating) { await ratingService.CreateAsync(mapper.Map <CompositionRatings>(rating)).ConfigureAwait(false); }