コード例 #1
0
        public async Task Rate(CreateRatingInput input)
        {
            try
            {
                var isAlreadyRate = await _ratingManager.IsUserAlreadyRatePost(AbpSession.UserId.Value, input.PostId);

                if (isAlreadyRate)
                {
                    throw new UserFriendlyException($"User {AbpSession.UserId} already rate post {input.PostId}");
                }

                await _ratingManager.Create(new Rating(input.Value, input.PostId, AbpSession.UserId.Value));

                var post = await _manager.GetById(input.PostId);

                var averageRating = await _ratingManager.GetRatingAverage(input.PostId);

                post.SetAverageRating(averageRating);
                await _manager.Update(post);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }