예제 #1
0
        public async Task <IActionResult> CreateRating([FromBody] RatingForCreate rating)
        {
            var createdRating = await _ratingService.CreateRating(rating);

            return(CreatedAtAction(
                       actionName: nameof(GetRatingById),
                       routeValues: new { ratingId = createdRating.RatingId },
                       value: createdRating));
        }
예제 #2
0
        public Task <RatingDetail> CreateRating(RatingForCreate rating)
        {
            if (rating is null)
            {
                throw new ArgumentNullException(nameof(rating));
            }

            return(CreateRating());

            async Task <RatingDetail> CreateRating()
            {
                var ratingForCreate = _mapper.Map <Rating>(rating);

                ratingForCreate.Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
                _context.Ratings.Add(ratingForCreate);
                await _context.SaveChangesAsync();

                return(await GetRating(ratingForCreate.RatingId)
                       ?? throw new InvalidOperationException("Expected a rating from create"));
            }
        }