Esempio n. 1
0
        public async Task <ActionResult> Like(int id)
        {
            var user = await _userRepository.GetByEmailAsync(GetUserId());

            if (user.IsBanned)
            {
                return(Forbid());
            }

            var surveyItem = await _surveyRepository.GetAsync(id);

            var likeItem = surveyItem.Survey.Likes.FirstOrDefault(p => p.SurveyId == id && p.UserId == user.Id);

            if (likeItem != null)
            {
                return(ValidationProblem());
            }

            await _surveyRepository.AddLikeAsync(new Like
            {
                SurveyId = id,
                UserId   = user.Id
            });

            return(Ok());
        }