Exemplo n.º 1
0
        public async Task <IActionResult> PostRatingAsync([FromBody] RatingDTO ratingDTO)
        {
            await Task.Yield();

            try
            {
                var ratedFilm = await filmLogic.GetAsync(ratingDTO.RatedFilmId).ConfigureAwait(false);

                var ratedByUser = await userLogic.GetAsync(ratingDTO.RatedById).ConfigureAwait(false);

                ratedByUser.Id      = ratingDTO.RatedById;
                ratingDTO.RatedBy   = new UserDTO(ratedByUser);
                ratingDTO.RatedFilm = new FilmDTO(ratedFilm);
                var rating = ratingDTO.ToEntity();
                var film   = await filmLogic.AddRatingAsync(rating).ConfigureAwait(false);

                return(Ok(new FilmDTO(film)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
 public void Rate(RatingDTO rating)
 {
     _fabric.CreateRatingsRepository().Create(rating.ToEntity());
 }