public async Task <ActionResult <RatingResponseModel> > Post(RatingInputModel input)
        {
            var userId = this.userManager.GetUserId(this.User);
            var ratingResponseModel = new RatingResponseModel();

            if (userId == null)
            {
                ratingResponseModel.AuthenticationErrorMessage = "Please log in in order to vote.";
                ratingResponseModel.Rating = this.ratingsService.GetRating(input.ProjectId);

                return(ratingResponseModel);
            }

            if (input.Rate < 1 || input.Rate > 5)
            {
                ratingResponseModel.Rating = this.ratingsService.GetRating(input.ProjectId);

                return(ratingResponseModel);
            }

            await this.ratingsService.RateAsync(input.ProjectId, userId, input.Rate);

            ratingResponseModel.Rating = this.ratingsService.GetRating(input.ProjectId);

            return(ratingResponseModel);
        }
        public async Task <RatingResponseModel> GetRating(int id)
        {
            var productRating = await this.ratingsService.GetProductAverageRating(id);

            var response = new RatingResponseModel
            {
                Rating = productRating,
            };

            return(response);
        }
Exemplo n.º 3
0
        public async Task <ActionResult <RatingResponseModel> > Post(RatingInputModel input)
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            await this.reviewService.CreateRating(input.MediaId, userId, input.Value);

            var ratingService = await this.reviewService.GetRatingAverageCount(input.MediaId);

            var average = ratingService.Item1;
            var count   = ratingService.Item2;

            var response = new RatingResponseModel()
            {
                TotalVotes = count, AverageVote = average,
            };

            return(response);
        }